Qt 4.8
qcombobox.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qcombobox.h"
43 
44 #ifndef QT_NO_COMBOBOX
45 #include <qstylepainter.h>
46 #include <qlineedit.h>
47 #include <qapplication.h>
48 #include <qdesktopwidget.h>
49 #include <qlistview.h>
50 #include <qtableview.h>
51 #include <qitemdelegate.h>
52 #include <qmap.h>
53 #include <qmenu.h>
54 #include <qevent.h>
55 #include <qlayout.h>
56 #include <qscrollbar.h>
57 #include <qtreeview.h>
58 #include <qheaderview.h>
59 #include <qmath.h>
60 #ifndef QT_NO_IM
61 #include "qinputcontext.h"
62 #endif
63 #include <private/qapplication_p.h>
64 #include <private/qcombobox_p.h>
65 #include <private/qabstractitemmodel_p.h>
66 #include <private/qabstractscrollarea_p.h>
67 #include <private/qsoftkeymanager_p.h>
68 #include <qdebug.h>
69 #ifdef Q_WS_X11
70 #include <private/qt_x11_p.h>
71 #endif
72 #if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC)
73 #include <private/qcore_mac_p.h>
74 #include <QMacStyle>
75 #include <private/qt_cocoa_helpers_mac_p.h>
76 #endif
77 #ifndef QT_NO_EFFECTS
78 # include <private/qeffects_p.h>
79 #endif
80 #if defined(Q_WS_S60)
81 #include "private/qt_s60_p.h"
82 #endif
83 #ifndef QT_NO_ACCESSIBILITY
84 #include "qaccessible.h"
85 #endif
86 
88 
90  : QWidgetPrivate(),
91  model(0),
92  lineEdit(0),
93  container(0),
94  insertPolicy(QComboBox::InsertAtBottom),
95  sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow),
96  minimumContentsLength(0),
97  shownOnce(false),
98  autoCompletion(true),
99  duplicatesEnabled(false),
100  frame(true),
101  maxVisibleItems(10),
102  maxCount(INT_MAX),
103  modelColumn(0),
104  inserting(false),
105  arrowState(QStyle::State_None),
106  hoverControl(QStyle::SC_None),
107  autoCompletionCaseSensitivity(Qt::CaseInsensitive),
108  indexBeforeChange(-1)
109 #ifndef QT_NO_COMPLETER
110  , completer(0)
111 #endif
112 {
113 }
114 
116  const QModelIndex &index) const
117 {
118  QStyleOptionMenuItem menuOption;
119 
120  QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));
121  QVariant value = index.data(Qt::ForegroundRole);
122  if (value.canConvert<QBrush>()) {
123  resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));
124  resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));
125  resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
126  }
127  menuOption.palette = resolvedpalette;
128  menuOption.state = QStyle::State_None;
129  if (mCombo->window()->isActiveWindow())
130  menuOption.state = QStyle::State_Active;
131  if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
132  menuOption.state |= QStyle::State_Enabled;
133  else
135  if (option.state & QStyle::State_Selected)
136  menuOption.state |= QStyle::State_Selected;
138  menuOption.checked = mCombo->currentIndex() == index.row();
141  else
143 
144  QVariant variant = index.model()->data(index, Qt::DecorationRole);
145  switch (variant.type()) {
146  case QVariant::Icon:
147  menuOption.icon = qvariant_cast<QIcon>(variant);
148  break;
149  case QVariant::Color: {
150  static QPixmap pixmap(option.decorationSize);
151  pixmap.fill(qvariant_cast<QColor>(variant));
152  menuOption.icon = pixmap;
153  break; }
154  default:
155  menuOption.icon = qvariant_cast<QPixmap>(variant);
156  break;
157  }
158  if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
160  qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
161  }
162  menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
163  .replace(QLatin1Char('&'), QLatin1String("&&"));
164  menuOption.tabWidth = 0;
165  menuOption.maxIconWidth = option.decorationSize.width() + 4;
166  menuOption.menuRect = option.rect;
167  menuOption.rect = option.rect;
168 
169  // Make sure fonts set on the combo box also overrides the font for the popup menu.
170  if (mCombo->testAttribute(Qt::WA_SetFont)
171  || mCombo->testAttribute(Qt::WA_MacSmallSize)
172  || mCombo->testAttribute(Qt::WA_MacMiniSize)
173  || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont()))
174  menuOption.font = mCombo->font();
175  else
176  menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
177 
178  menuOption.fontMetrics = QFontMetrics(menuOption.font);
179 
180  return menuOption;
181 }
182 
183 #ifdef QT_KEYPAD_NAVIGATION
184 void QComboBoxPrivate::_q_completerActivated()
185 {
186  Q_Q(QComboBox);
187  if ( QApplication::keypadNavigationEnabled()
188  && q->isEditable()
189  && q->completer()
190  && q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) {
191  q->setEditFocus(false);
192  }
193 }
194 #endif
195 
197 {
198  Q_Q(QComboBox);
199  if (arrowState == state)
200  return;
201  arrowState = state;
203  q->initStyleOption(&opt);
204  q->update(q->style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, q));
205 }
206 
208 {
209  Q_Q(QComboBox);
210  if (lineEdit) {
213  }
216  q->update();
217 }
218 
220 {
222 }
223 
224 
225 //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't
227 {
228 #ifdef Q_WS_WIN
229  return QApplication::desktop()->screenGeometry(screen);
230 #elif defined Q_WS_X11
231  if (X11->desktopEnvironment == DE_KDE)
232  return QApplication::desktop()->screenGeometry(screen);
233  else
234  return QApplication::desktop()->availableGeometry(screen);
235 #else
236  return QApplication::desktop()->availableGeometry(screen);
237 #endif
238 }
239 
241 {
242 
243  Q_Q(QComboBox);
244  QRect lastHoverRect = hoverRect;
245  QStyle::SubControl lastHoverControl = hoverControl;
246  bool doesHover = q->testAttribute(Qt::WA_Hover);
247  if (lastHoverControl != newHoverControl(pos) && doesHover) {
248  q->update(lastHoverRect);
249  q->update(hoverRect);
250  return true;
251  }
252  return !doesHover;
253 }
254 
256 {
257  Q_Q(QComboBox);
259  q->initStyleOption(&opt);
261  hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);
263  ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)
264  : QRect();
265  return hoverControl;
266 }
267 
268 /*
269  Computes a size hint based on the maximum width
270  for the items in the combobox.
271 */
273 {
274  Q_Q(const QComboBox);
275 
276  int width = 0;
277  const int count = q->count();
278  const int iconWidth = q->iconSize().width() + 4;
279  const QFontMetrics &fontMetrics = q->fontMetrics();
280 
281  for (int i = 0; i < count; ++i) {
282  const int textWidth = fontMetrics.width(q->itemText(i));
283  if (q->itemIcon(i).isNull())
284  width = (qMax(width, textWidth));
285  else
286  width = (qMax(width, textWidth + iconWidth));
287  }
288 
290  q->initStyleOption(&opt);
291  QSize tmp(width, 0);
292  tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);
293  return tmp.width();
294 }
295 
297 {
298  Q_Q(const QComboBox);
299  if (!sh.isValid()) {
301  int count = q->count();
302  QSize iconSize = q->iconSize();
303  const QFontMetrics &fm = q->fontMetrics();
304 
305  // text width
306  if (&sh == &sizeHint || minimumContentsLength == 0) {
307  switch (sizeAdjustPolicy) {
310  if (count == 0) {
311  sh.rwidth() = 7 * fm.width(QLatin1Char('x'));
312  } else {
313  for (int i = 0; i < count; ++i) {
314  if (!q->itemIcon(i).isNull()) {
315  hasIcon = true;
316  sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));
317  } else {
318  sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));
319  }
320  }
321  }
322  break;
324  for (int i = 0; i < count && !hasIcon; ++i)
325  hasIcon = !q->itemIcon(i).isNull();
326  default:
327  ;
328  }
329  } else {
330  for (int i = 0; i < count && !hasIcon; ++i)
331  hasIcon = !q->itemIcon(i).isNull();
332  }
333  if (minimumContentsLength > 0)
334  sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
335 
336 
337  // height
338  sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);
339  if (hasIcon) {
340  sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
341  }
342 
343  // add style and strut values
345  q->initStyleOption(&opt);
346  sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);
347  }
349 }
350 
352 {
354 }
355 
357 {
358  Q_Q(const QComboBox);
360  q->initStyleOption(&opt);
362  q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q));
363  if (lineEdit)
365  if (container)
367 }
368 
369 
371 {
372  if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
373  adjustSizeTimer.stop();
374  if (combo->sizeAdjustPolicy() == QComboBox::AdjustToContents) {
375  combo->updateGeometry();
376  combo->adjustSize();
377  combo->update();
378  }
379  }
380 }
381 
383 {
384  QStyleOptionComboBox opt = comboStyleOption();
385  if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
386  QStyleOption myOpt;
387  myOpt.initFrom(this);
389  if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
390  setMask(mask.region);
391  }
392  } else {
393  clearMask();
394  }
396 }
397 
399 {
400 // On Mac using the Mac style we want to clear the selection
401 // when the mouse moves outside the popup.
402 #ifdef Q_WS_MAC
403  QStyleOptionComboBox opt = comboStyleOption();
404  if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo))
405  view->clearSelection();
406 #endif
407 }
408 
410  : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0)
411 {
412  // we need the combobox and itemview
413  Q_ASSERT(parent);
414  Q_ASSERT(itemView);
415 
418 
419  // setup container
421 
422  // we need a vertical layout
424  layout->setSpacing(0);
425  layout->setMargin(0);
426 
427  // set item view
428  setItemView(itemView);
429 
430  // add scroller arrows if style needs them
432  const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
433  if (usePopup) {
436  top->hide();
437  bottom->hide();
438  } else {
439  setLineWidth(1);
440  }
441 
443 
444  if (top) {
445  layout->insertWidget(0, top);
446  connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
447  }
448  if (bottom) {
449  layout->addWidget(bottom);
450  connect(bottom, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
451  }
452 
453  // Some styles (Mac) have a margin at the top and bottom of the popup.
454  layout->insertSpacing(0, 0);
455  layout->addSpacing(0);
457 }
458 
460 {
461 #ifndef QT_NO_SCROLLBAR
462  if (view->verticalScrollBar())
463  view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
464 #endif
465 }
466 
467 /*
468  Hides or shows the scrollers when we emulate a popupmenu
469 */
471 {
472 #ifndef QT_NO_SCROLLBAR
473  if (!top || !bottom)
474  return;
475 
476  if (isVisible() == false)
477  return;
478 
482 
483  bool needTop = view->verticalScrollBar()->value()
484  > (view->verticalScrollBar()->minimum() + spacing());
485  bool needBottom = view->verticalScrollBar()->value()
486  < (view->verticalScrollBar()->maximum() - spacing()*2);
487  if (needTop)
488  top->show();
489  else
490  top->hide();
491  if (needBottom)
492  bottom->show();
493  else
494  bottom->hide();
495  } else {
496  top->hide();
497  bottom->hide();
498  }
499 #endif // QT_NO_SCROLLBAR
500 }
501 
502 /*
503  Cleans up when the view is destroyed.
504 */
506 {
507  view = 0;
509 }
510 
511 /*
512  Returns the item view used for the combobox popup.
513 */
515 {
516  return view;
517 }
518 
523 {
524  Q_ASSERT(itemView);
525 
526  // clean up old one
527  if (view) {
528  view->removeEventFilter(this);
529  view->viewport()->removeEventFilter(this);
530 #ifndef QT_NO_SCROLLBAR
531  disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
532  this, SLOT(updateScrollers()));
533  disconnect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
534  this, SLOT(updateScrollers()));
535 #endif
537  this, SLOT(viewDestroyed()));
538 
539  delete view;
540  view = 0;
541  }
542 
543  // setup the item view
544  view = itemView;
545  view->setParent(this);
547  qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);
549  view->installEventFilter(this);
550  view->viewport()->installEventFilter(this);
553  const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
554 #ifndef QT_NO_SCROLLBAR
555 #ifndef Q_WS_S60
556  if (usePopup)
558 #endif
559 #endif
561  usePopup) {
562  view->setMouseTracking(true);
563  }
566  view->setLineWidth(0);
568 #ifndef QT_NO_SCROLLBAR
569  connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
570  this, SLOT(updateScrollers()));
571  connect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
572  this, SLOT(updateScrollers()));
573 #endif
575  this, SLOT(viewDestroyed()));
576 
577 #ifdef QT_SOFTKEYS_ENABLED
580  addAction(selectAction);
581  addAction(cancelAction);
582 #endif
583 }
584 
589 {
590  QListView *lview = qobject_cast<QListView*>(view);
591  if (lview)
592  return lview->spacing();
593 #ifndef QT_NO_TABLEVIEW
595  if (tview)
596  return tview->showGrid() ? 1 : 0;
597 #endif
598  return 0;
599 }
600 
602 {
603  if (!layout() || layout()->count() < 1)
604  return;
605 
606  QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());
607  if (!boxLayout)
608  return;
609 
611  const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
612  const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
613 
614  QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();
615  if (topSpacer)
616  topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
617 
618  QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();
619  if (bottomSpacer && bottomSpacer != topSpacer)
620  bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
621 
622  boxLayout->invalidate();
623 }
624 
626 {
627  if (e->type() == QEvent::StyleChange) {
632 #ifdef QT_SOFTKEYS_ENABLED
633  } else if (e->type() == QEvent::LanguageChange) {
636 #endif
637  }
638 
640 }
641 
642 
644 {
645  switch (e->type()) {
647  switch (static_cast<QKeyEvent*>(e)->key()) {
648  case Qt::Key_Enter:
649  case Qt::Key_Return:
650 #ifdef QT_KEYPAD_NAVIGATION
651  case Qt::Key_Select:
652 #endif
654  combo->hidePopup();
656  }
657  return true;
658  case Qt::Key_Down:
659  if (!(static_cast<QKeyEvent*>(e)->modifiers() & Qt::AltModifier))
660  break;
661  // fall through
662  case Qt::Key_F4:
663  case Qt::Key_Escape:
664  combo->hidePopup();
665  return true;
666  default:
667  break;
668  }
669  break;
670  case QEvent::MouseMove:
671  if (isVisible()) {
672  QMouseEvent *m = static_cast<QMouseEvent *>(e);
673  QWidget *widget = static_cast<QWidget *>(o);
674  QPoint vector = widget->mapToGlobal(m->pos()) - initialClickPosition;
675  if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
677  QModelIndex indexUnderMouse = view->indexAt(m->pos());
678  if (indexUnderMouse.isValid()
679  && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
680  view->setCurrentIndex(indexUnderMouse);
681  }
682  }
683  break;
685  QMouseEvent *m = static_cast<QMouseEvent *>(e);
686  if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
690  combo->hidePopup();
692  return true;
693  }
694  break;
695  }
696  default:
697  break;
698  }
699  return QFrame::eventFilter(o, e);
700 }
701 
703 {
704  combo->update();
705 }
706 
708 {
709  emit resetButton();
710  combo->update();
711 #ifndef QT_NO_GRAPHICSVIEW
712  // QGraphicsScenePrivate::removePopup closes the combo box popup, it hides it non-explicitly.
713  // Hiding/showing the QComboBox after this will unexpectedly show the popup as well.
714  // Re-hiding the popup container makes sure it is explicitly hidden.
716  proxy->hide();
717 #endif
718 }
719 
721 {
722 
728  combo);
729  if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
730  || (!combo->isEditable() && sc != QStyle::SC_None))
732  combo->hidePopup();
733 }
734 
736 {
737  Q_UNUSED(e);
739  combo->hidePopup();
740  emit resetButton();
741  }
742 }
743 
745 {
746  // ### This should use QComboBox's initStyleOption(), but it's protected
747  // perhaps, we could cheat by having the QCombo private instead?
749  opt.initFrom(combo);
752  opt.editable = combo->isEditable();
753  return opt;
754 }
755 
871  : QWidget(*new QComboBoxPrivate(), parent, 0)
872 {
873  Q_D(QComboBox);
874  d->init();
875 }
876 
881  : QWidget(dd, parent, 0)
882 {
883  Q_D(QComboBox);
884  d->init();
885 }
886 
887 #ifdef QT3_SUPPORT
888 
893  : QWidget(*new QComboBoxPrivate(), parent, 0)
894 {
895  Q_D(QComboBox);
896  d->init();
898 }
899 
904 QComboBox::QComboBox(bool rw, QWidget *parent, const char *name)
905  : QWidget(*new QComboBoxPrivate(), parent, 0)
906 {
907  Q_D(QComboBox);
908  d->init();
909  setEditable(rw);
911 }
912 
913 #endif //QT3_SUPPORT
914 
992 {
993  Q_Q(QComboBox);
994  q->setFocusPolicy(Qt::WheelFocus);
998  q->setModel(new QStandardItemModel(0, 1, q));
999  if (!q->isEditable())
1000  q->setAttribute(Qt::WA_InputMethodEnabled, false);
1001  else
1002  q->setAttribute(Qt::WA_InputMethodEnabled);
1003 }
1004 
1006 {
1007  if (container)
1008  return container;
1009 
1010  Q_Q(QComboBox);
1011  container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);
1012  container->itemView()->setModel(model);
1013  container->itemView()->setTextElideMode(Qt::ElideMiddle);
1014  updateDelegate(true);
1015  updateLayoutDirection();
1016  updateViewContainerPaletteAndOpacity();
1017  QObject::connect(container, SIGNAL(itemSelected(QModelIndex)),
1018  q, SLOT(_q_itemSelected(QModelIndex)));
1019  QObject::connect(container->itemView()->selectionModel(),
1020  SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1021  q, SLOT(_q_emitHighlighted(QModelIndex)));
1022  QObject::connect(container, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));
1023  return container;
1024 }
1025 
1026 
1028 {
1029  updateArrow(QStyle::State_None);
1030 }
1031 
1032 void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
1033 {
1034  Q_Q(QComboBox);
1035  if (inserting || topLeft.parent() != root)
1036  return;
1037 
1039  sizeHint = QSize();
1040  adjustComboBoxSize();
1041  q->updateGeometry();
1042  }
1043 
1044  if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
1045  if (lineEdit) {
1046  lineEdit->setText(q->itemText(currentIndex.row()));
1047  updateLineEditGeometry();
1048  }
1049  q->update();
1050  }
1051 #ifndef QT_NO_ACCESSIBILITY
1053 #endif
1054 }
1055 
1056 void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end)
1057 {
1058  Q_Q(QComboBox);
1059  if (inserting || parent != root)
1060  return;
1061 
1063  sizeHint = QSize();
1064  adjustComboBoxSize();
1065  q->updateGeometry();
1066  }
1067 
1068  // set current index if combo was previously empty
1069  if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid()) {
1070  q->setCurrentIndex(0);
1071  // need to emit changed if model updated index "silently"
1072  } else if (currentIndex.row() != indexBeforeChange) {
1073  q->update();
1074  _q_emitCurrentIndexChanged(currentIndex);
1075  }
1076 }
1077 
1079 {
1080  indexBeforeChange = currentIndex.row();
1081 }
1082 
1083 void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/)
1084 {
1085  Q_Q(QComboBox);
1086  if (parent != root)
1087  return;
1088 
1090  sizeHint = QSize();
1091  adjustComboBoxSize();
1092  q->updateGeometry();
1093  }
1094 
1095  // model has changed the currentIndex
1096  if (currentIndex.row() != indexBeforeChange) {
1097  if (!currentIndex.isValid() && q->count()) {
1098  q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));
1099  return;
1100  }
1101  if (lineEdit) {
1102  lineEdit->setText(q->itemText(currentIndex.row()));
1103  updateLineEditGeometry();
1104  }
1105  q->update();
1106  _q_emitCurrentIndexChanged(currentIndex);
1107  }
1108 }
1109 
1110 
1112 {
1113  if (!container)
1114  return;
1115  Q_Q(QComboBox);
1117  q->initStyleOption(&opt);
1118 #ifndef QT_NO_MENU
1119  if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1120  QMenu menu;
1121  menu.ensurePolished();
1122  container->setPalette(menu.palette());
1123  container->setWindowOpacity(menu.windowOpacity());
1124  } else
1125 #endif
1126  {
1127  container->setPalette(q->palette());
1128  container->setWindowOpacity(1.0);
1129  }
1130  if (lineEdit)
1131  lineEdit->setPalette(q->palette());
1132 }
1133 
1142 {
1143  if (!option)
1144  return;
1145 
1146  Q_D(const QComboBox);
1147  option->initFrom(this);
1148  option->editable = isEditable();
1149  option->frame = d->frame;
1150  if (hasFocus() && !option->editable)
1151  option->state |= QStyle::State_Selected;
1152  option->subControls = QStyle::SC_All;
1153  if (d->arrowState == QStyle::State_Sunken) {
1155  option->state |= d->arrowState;
1156  } else {
1157  option->activeSubControls = d->hoverControl;
1158  }
1159  if (d->currentIndex.isValid()) {
1160  option->currentText = currentText();
1161  option->currentIcon = d->itemIcon(d->currentIndex);
1162  }
1163  option->iconSize = iconSize();
1164  if (d->container && d->container->isVisible())
1165  option->state |= QStyle::State_On;
1166 }
1167 
1169 {
1170  if (!lineEdit)
1171  return;
1172 
1173  Q_Q(QComboBox);
1175  q->initStyleOption(&opt);
1176  QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,
1178  if (!q->itemIcon(q->currentIndex()).isNull()) {
1179  QRect comboRect(editRect);
1180  editRect.setWidth(editRect.width() - q->iconSize().width() - 4);
1181  editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,
1182  editRect.size(), comboRect);
1183  }
1184  lineEdit->setGeometry(editRect);
1185 }
1186 
1187 Qt::MatchFlags QComboBoxPrivate::matchFlags() const
1188 {
1189  // Base how duplicates are determined on the autocompletion case sensitivity
1190  Qt::MatchFlags flags = Qt::MatchFixedString;
1191 #ifndef QT_NO_COMPLETER
1193 #endif
1194  flags |= Qt::MatchCaseSensitive;
1195  return flags;
1196 }
1197 
1198 
1200 {
1201  Q_Q(QComboBox);
1202  if (lineEdit && !lineEdit->text().isEmpty()) {
1203  //here we just check if the current item was entered
1204  const int index = q_func()->findText(lineEdit->text(), matchFlags());
1205  if (index != -1 && itemText(currentIndex) != lineEdit->text()) {
1206  q->setCurrentIndex(index);
1207  emitActivated(currentIndex);
1208  }
1209  }
1210 
1211 }
1212 
1214 {
1215  Q_Q(QComboBox);
1216  if (lineEdit && !lineEdit->text().isEmpty()) {
1217  if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
1218  return;
1219  lineEdit->deselect();
1220  lineEdit->end(false);
1221  QString text = lineEdit->text();
1222  // check for duplicates (if not enabled) and quit
1223  int index = -1;
1224  if (!duplicatesEnabled) {
1225  index = q->findText(text, matchFlags());
1226  if (index != -1) {
1227  q->setCurrentIndex(index);
1228  emitActivated(currentIndex);
1229  return;
1230  }
1231  }
1232  switch (insertPolicy) {
1234  index = 0;
1235  break;
1237  index = q->count();
1238  break;
1242  if (!q->count() || !currentIndex.isValid())
1243  index = 0;
1245  q->setItemText(q->currentIndex(), text);
1247  index = q->currentIndex() + 1;
1249  index = q->currentIndex();
1250  break;
1252  index = 0;
1253  for (int i=0; i< q->count(); i++, index++ ) {
1254  if (text.toLower() < q->itemText(i).toLower())
1255  break;
1256  }
1257  break;
1258  case QComboBox::NoInsert:
1259  default:
1260  break;
1261  }
1262  if (index >= 0) {
1263  q->insertItem(index, text);
1264  q->setCurrentIndex(index);
1265  emitActivated(currentIndex);
1266  }
1267  }
1268 }
1269 
1271 {
1272  Q_Q(QComboBox);
1273  if (item != currentIndex) {
1274  setCurrentIndex(item);
1275  } else if (lineEdit) {
1276  lineEdit->selectAll();
1277  lineEdit->setText(q->itemText(currentIndex.row()));
1278  }
1279  emitActivated(currentIndex);
1280 }
1281 
1283 {
1284  Q_Q(QComboBox);
1285  if (!index.isValid())
1286  return;
1287  QString text(itemText(index));
1288  emit q->activated(index.row());
1289  emit q->activated(text);
1290 }
1291 
1293 {
1294  Q_Q(QComboBox);
1295  if (!index.isValid())
1296  return;
1297  QString text(itemText(index));
1298  emit q->highlighted(index.row());
1299  emit q->highlighted(text);
1300 }
1301 
1303 {
1304  Q_Q(QComboBox);
1305  emit q->currentIndexChanged(index.row());
1306  emit q->currentIndexChanged(itemText(index));
1307 #ifndef QT_NO_ACCESSIBILITY
1309 #endif
1310 }
1311 
1313 {
1314  return index.isValid() ? model->data(index, itemRole()).toString() : QString();
1315 }
1316 
1318 {
1319  return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
1320 }
1321 
1326 {
1327  // ### check delegateparent and delete delegate if us?
1328  Q_D(QComboBox);
1329 
1330  QT_TRY {
1331  disconnect(d->model, SIGNAL(destroyed()),
1332  this, SLOT(_q_modelDestroyed()));
1333  } QT_CATCH(...) {
1334  ; // objects can't throw in destructor
1335  }
1336 }
1337 
1350 int QComboBox::maxVisibleItems() const
1351 {
1352  Q_D(const QComboBox);
1353  return d->maxVisibleItems;
1354 }
1355 
1357 {
1358  Q_D(QComboBox);
1359  if (maxItems < 0) {
1360  qWarning("QComboBox::setMaxVisibleItems: "
1361  "Invalid max visible items (%d) must be >= 0", maxItems);
1362  return;
1363  }
1364  d->maxVisibleItems = maxItems;
1365 }
1366 
1376 int QComboBox::count() const
1377 {
1378  Q_D(const QComboBox);
1379  return d->model->rowCount(d->root);
1380 }
1381 
1398 {
1399  Q_D(QComboBox);
1400  if (max < 0) {
1401  qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
1402  return;
1403  }
1404 
1405  if (max < count())
1406  d->model->removeRows(max, count() - max, d->root);
1407 
1408  d->maxCount = max;
1409 }
1410 
1411 int QComboBox::maxCount() const
1412 {
1413  Q_D(const QComboBox);
1414  return d->maxCount;
1415 }
1416 
1417 #ifndef QT_NO_COMPLETER
1418 
1443 bool QComboBox::autoCompletion() const
1444 {
1445  Q_D(const QComboBox);
1446  return d->autoCompletion;
1447 }
1448 
1458 {
1459  Q_D(QComboBox);
1460 
1461 #ifdef QT_KEYPAD_NAVIGATION
1462  if (QApplication::keypadNavigationEnabled() && !enable && isEditable())
1463  qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
1464 #endif
1465 
1466  d->autoCompletion = enable;
1467  if (!d->lineEdit)
1468  return;
1469  if (enable) {
1470  if (d->lineEdit->completer())
1471  return;
1472  d->completer = new QCompleter(d->model, d->lineEdit);
1473  d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);
1474  d->completer->setCompletionMode(QCompleter::InlineCompletion);
1475  d->completer->setCompletionColumn(d->modelColumn);
1476  d->lineEdit->setCompleter(d->completer);
1477  d->completer->setWidget(this);
1478  } else {
1479  d->lineEdit->setCompleter(0);
1480  }
1481 }
1482 
1508 {
1509  Q_D(const QComboBox);
1510  return d->autoCompletionCaseSensitivity;
1511 }
1512 
1522 {
1523  Q_D(QComboBox);
1524  d->autoCompletionCaseSensitivity = sensitivity;
1525  if (d->lineEdit && d->lineEdit->completer())
1526  d->lineEdit->completer()->setCaseSensitivity(sensitivity);
1527 }
1528 
1529 #endif // QT_NO_COMPLETER
1530 
1543 bool QComboBox::duplicatesEnabled() const
1544 {
1545  Q_D(const QComboBox);
1546  return d->duplicatesEnabled;
1547 }
1548 
1550 {
1551  Q_D(QComboBox);
1552  d->duplicatesEnabled = enable;
1553 }
1554 
1572 int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const
1573 {
1574  Q_D(const QComboBox);
1575  QModelIndexList result;
1576  QModelIndex start = d->model->index(0, d->modelColumn, d->root);
1577  result = d->model->match(start, role, data, 1, flags);
1578  if (result.isEmpty())
1579  return -1;
1580  return result.first().row();
1581 }
1582 
1598 {
1599  Q_D(const QComboBox);
1600  return d->insertPolicy;
1601 }
1602 
1604 {
1605  Q_D(QComboBox);
1606  d->insertPolicy = policy;
1607 }
1608 
1623 {
1624  Q_D(const QComboBox);
1625  return d->sizeAdjustPolicy;
1626 }
1627 
1629 {
1630  Q_D(QComboBox);
1631  if (policy == d->sizeAdjustPolicy)
1632  return;
1633 
1634  d->sizeAdjustPolicy = policy;
1635  d->sizeHint = QSize();
1636  d->adjustComboBoxSize();
1637  updateGeometry();
1638 }
1639 
1655 {
1656  Q_D(const QComboBox);
1657  return d->minimumContentsLength;
1658 }
1659 
1661 {
1662  Q_D(QComboBox);
1663  if (characters == d->minimumContentsLength || characters < 0)
1664  return;
1665 
1666  d->minimumContentsLength = characters;
1667 
1668  if (d->sizeAdjustPolicy == AdjustToContents
1669  || d->sizeAdjustPolicy == AdjustToMinimumContentsLength
1670  || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
1671  d->sizeHint = QSize();
1672  d->adjustComboBoxSize();
1673  updateGeometry();
1674  }
1675 }
1676 
1689 QSize QComboBox::iconSize() const
1690 {
1691  Q_D(const QComboBox);
1692  if (d->iconSize.isValid())
1693  return d->iconSize;
1694 
1695  int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
1696  return QSize(iconWidth, iconWidth);
1697 }
1698 
1700 {
1701  Q_D(QComboBox);
1702  if (size == d->iconSize)
1703  return;
1704 
1705  view()->setIconSize(size);
1706  d->iconSize = size;
1707  d->sizeHint = QSize();
1708  updateGeometry();
1709 }
1710 
1724 {
1725  Q_D(const QComboBox);
1726  return d->lineEdit != 0;
1727 }
1728 
1737 {
1738  Q_Q(QComboBox);
1740  q->initStyleOption(&opt);
1741  if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1742  if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
1743  q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
1744  } else {
1745  if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
1746  q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
1747  }
1748 }
1749 
1751 {
1752  QVariant decoration = model->data(index, Qt::DecorationRole);
1753  if (decoration.type() == QVariant::Pixmap)
1754  return QIcon(qvariant_cast<QPixmap>(decoration));
1755  else
1756  return qvariant_cast<QIcon>(decoration);
1757 }
1758 
1760 {
1761  Q_D(QComboBox);
1762  if (isEditable() == editable)
1763  return;
1764 
1765  d->updateDelegate();
1766 
1768  initStyleOption(&opt);
1769  if (editable) {
1770  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1771  d->viewContainer()->updateScrollers();
1773  }
1774  QLineEdit *le = new QLineEdit(this);
1775  setLineEdit(le);
1776  } else {
1777  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1778  d->viewContainer()->updateScrollers();
1780  }
1782  d->lineEdit->hide();
1783  d->lineEdit->deleteLater();
1784  d->lineEdit = 0;
1785  }
1786 
1787  d->viewContainer()->updateTopBottomMargin();
1789  adjustSize();
1790 }
1791 
1798 {
1799  Q_D(QComboBox);
1800  if (!edit) {
1801  qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
1802  return;
1803  }
1804 
1805  if (edit == d->lineEdit)
1806  return;
1807 
1808  edit->setText(currentText());
1809  delete d->lineEdit;
1810 
1811  d->lineEdit = edit;
1812  if (d->lineEdit->parent() != this)
1813  d->lineEdit->setParent(this);
1814  connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));
1815  connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished()));
1816  connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString)));
1817 #ifdef QT3_SUPPORT
1818  connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
1819 #endif
1820  d->lineEdit->setFrame(false);
1821  d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
1822  d->lineEdit->setFocusProxy(this);
1823  d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
1824 #ifndef QT_NO_COMPLETER
1825  setAutoCompletion(d->autoCompletion);
1826 #endif
1827 
1828 #ifdef QT_KEYPAD_NAVIGATION
1829 #ifndef QT_NO_COMPLETER
1830  if (QApplication::keypadNavigationEnabled()) {
1831  // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
1832  // This means that when the user enters edit mode they are immediately presented with a
1833  // list of possible completions.
1834  setAutoCompletion(true);
1835  if (d->completer) {
1836  d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
1837  connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated()));
1838  }
1839  }
1840 #endif
1841 #endif
1842 
1844  d->updateLayoutDirection();
1845  d->updateLineEditGeometry();
1846  if (isVisible())
1847  d->lineEdit->show();
1848 
1849  update();
1850 }
1851 
1859 {
1860  Q_D(const QComboBox);
1861  return d->lineEdit;
1862 }
1863 
1864 #ifndef QT_NO_VALIDATOR
1865 
1872 {
1873  Q_D(QComboBox);
1874  if (d->lineEdit)
1875  d->lineEdit->setValidator(v);
1876 }
1877 
1885 {
1886  Q_D(const QComboBox);
1887  return d->lineEdit ? d->lineEdit->validator() : 0;
1888 }
1889 #endif // QT_NO_VALIDATOR
1890 
1891 #ifndef QT_NO_COMPLETER
1892 
1904 {
1905  Q_D(QComboBox);
1906  if (!d->lineEdit)
1907  return;
1908  d->lineEdit->setCompleter(c);
1909  if (c)
1910  c->setWidget(this);
1911 }
1912 
1925 {
1926  Q_D(const QComboBox);
1927  return d->lineEdit ? d->lineEdit->completer() : 0;
1928 }
1929 
1930 #endif // QT_NO_COMPLETER
1931 
1938 {
1939  return view()->itemDelegate();
1940 }
1941 
1955 {
1956  if (!delegate) {
1957  qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
1958  return;
1959  }
1960  delete view()->itemDelegate();
1961  view()->setItemDelegate(delegate);
1962 }
1963 
1969 {
1970  Q_D(const QComboBox);
1972  QComboBox *that = const_cast<QComboBox*>(this);
1973  that->setModel(new QStandardItemModel(0, 1, that));
1974  }
1975  return d->model;
1976 }
1977 
1985 {
1986  Q_D(QComboBox);
1987 
1988  if (!model) {
1989  qWarning("QComboBox::setModel: cannot set a 0 model");
1990  return;
1991  }
1992 
1993 #ifndef QT_NO_COMPLETER
1994  if (d->lineEdit && d->lineEdit->completer()
1995  && d->lineEdit->completer() == d->completer)
1996  d->lineEdit->completer()->setModel(model);
1997 #endif
1998  if (d->model) {
1999  disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
2000  this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2001  disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2002  this, SLOT(_q_updateIndexBeforeChange()));
2003  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2004  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2005  disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2006  this, SLOT(_q_updateIndexBeforeChange()));
2007  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2008  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2009  disconnect(d->model, SIGNAL(destroyed()),
2010  this, SLOT(_q_modelDestroyed()));
2011  disconnect(d->model, SIGNAL(modelAboutToBeReset()),
2012  this, SLOT(_q_updateIndexBeforeChange()));
2013  disconnect(d->model, SIGNAL(modelReset()),
2014  this, SLOT(_q_modelReset()));
2015  if (d->model->QObject::parent() == this)
2016  delete d->model;
2017  }
2018 
2019  d->model = model;
2020 
2021  connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
2022  this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2023  connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2024  this, SLOT(_q_updateIndexBeforeChange()));
2025  connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2026  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2027  connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2028  this, SLOT(_q_updateIndexBeforeChange()));
2029  connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2030  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2031  connect(model, SIGNAL(destroyed()),
2032  this, SLOT(_q_modelDestroyed()));
2033  connect(model, SIGNAL(modelAboutToBeReset()),
2034  this, SLOT(_q_updateIndexBeforeChange()));
2035  connect(model, SIGNAL(modelReset()),
2036  this, SLOT(_q_modelReset()));
2037 
2038  if (d->container)
2039  d->container->itemView()->setModel(model);
2040 
2041  bool currentReset = false;
2042 
2043  if (count()) {
2044  for (int pos=0; pos < count(); pos++) {
2045  if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
2047  currentReset = true;
2048  break;
2049  }
2050  }
2051  }
2052 
2053  if (!currentReset)
2054  setCurrentIndex(-1);
2055 
2056  d->modelChanged();
2057 }
2058 
2066 {
2067  Q_D(const QComboBox);
2068  return QModelIndex(d->root);
2069 }
2070 
2077 {
2078  Q_D(QComboBox);
2079  d->root = QPersistentModelIndex(index);
2080  view()->setRootIndex(index);
2081  update();
2082 }
2083 
2096 int QComboBox::currentIndex() const
2097 {
2098  Q_D(const QComboBox);
2099  return d->currentIndex.row();
2100 }
2101 
2103 {
2104  Q_D(QComboBox);
2105  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2106  d->setCurrentIndex(mi);
2107 }
2108 
2110 {
2111  Q_Q(QComboBox);
2112 
2113  QModelIndex normalized;
2114  if (mi.column() != modelColumn)
2115  normalized = model->index(mi.row(), modelColumn, mi.parent());
2116  if (!normalized.isValid())
2117  normalized = mi; // Fallback to passed index.
2118 
2119  bool indexChanged = (normalized != currentIndex);
2120  if (indexChanged)
2121  currentIndex = QPersistentModelIndex(normalized);
2122  if (lineEdit) {
2123  QString newText = q->itemText(normalized.row());
2124  if (lineEdit->text() != newText)
2125  lineEdit->setText(newText);
2126  updateLineEditGeometry();
2127  }
2128  if (indexChanged) {
2129  q->update();
2130  _q_emitCurrentIndexChanged(currentIndex);
2131  }
2132 }
2133 
2148 {
2149  Q_D(const QComboBox);
2150  if (d->lineEdit)
2151  return d->lineEdit->text();
2152  else if (d->currentIndex.isValid())
2153  return d->itemText(d->currentIndex);
2154  else
2155  return QString();
2156 }
2157 
2162 {
2163  Q_D(const QComboBox);
2164  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2165  return d->itemText(mi);
2166 }
2167 
2172 {
2173  Q_D(const QComboBox);
2174  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2175  return d->itemIcon(mi);
2176 }
2177 
2182 QVariant QComboBox::itemData(int index, int role) const
2183 {
2184  Q_D(const QComboBox);
2185  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2186  return d->model->data(mi, role);
2187 }
2188 
2218 void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)
2219 {
2220  Q_D(QComboBox);
2221  int itemCount = count();
2222  index = qBound(0, index, itemCount);
2223  if (index >= d->maxCount)
2224  return;
2225 
2226  // For the common case where we are using the built in QStandardItemModel
2227  // construct a QStandardItem, reducing the number of expensive signals from the model
2228  if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2229  QStandardItem *item = new QStandardItem(text);
2230  if (!icon.isNull()) item->setData(icon, Qt::DecorationRole);
2231  if (userData.isValid()) item->setData(userData, Qt::UserRole);
2232  m->insertRow(index, item);
2233  ++itemCount;
2234  } else {
2235  d->inserting = true;
2236  if (d->model->insertRows(index, 1, d->root)) {
2237  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2238  if (icon.isNull() && !userData.isValid()) {
2239  d->model->setData(item, text, Qt::EditRole);
2240  } else {
2242  if (!text.isNull()) values.insert(Qt::EditRole, text);
2243  if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
2244  if (userData.isValid()) values.insert(Qt::UserRole, userData);
2245  if (!values.isEmpty()) d->model->setItemData(item, values);
2246  }
2247  d->inserting = false;
2248  d->_q_rowsInserted(d->root, index, index);
2249  ++itemCount;
2250  } else {
2251  d->inserting = false;
2252  }
2253  }
2254 
2255  if (itemCount > d->maxCount)
2256  d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
2257 }
2258 
2270 {
2271  Q_D(QComboBox);
2272  if (list.isEmpty())
2273  return;
2274  index = qBound(0, index, count());
2275  int insertCount = qMin(d->maxCount - index, list.count());
2276  if (insertCount <= 0)
2277  return;
2278  // For the common case where we are using the built in QStandardItemModel
2279  // construct a QStandardItem, reducing the number of expensive signals from the model
2280  if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2281  QList<QStandardItem *> items;
2282  QStandardItem *hiddenRoot = m->invisibleRootItem();
2283  for (int i = 0; i < insertCount; ++i)
2284  items.append(new QStandardItem(list.at(i)));
2285  hiddenRoot->insertRows(index, items);
2286  } else {
2287  d->inserting = true;
2288  if (d->model->insertRows(index, insertCount, d->root)) {
2289  QModelIndex item;
2290  for (int i = 0; i < insertCount; ++i) {
2291  item = d->model->index(i+index, d->modelColumn, d->root);
2292  d->model->setData(item, list.at(i), Qt::EditRole);
2293  }
2294  d->inserting = false;
2295  d->_q_rowsInserted(d->root, index, index + insertCount - 1);
2296  } else {
2297  d->inserting = false;
2298  }
2299  }
2300 
2301  int mc = count();
2302  if (mc > d->maxCount)
2303  d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);
2304 }
2305 
2321 {
2322  Q_D(QComboBox);
2323  int itemCount = count();
2324  index = qBound(0, index, itemCount);
2325  if (index >= d->maxCount)
2326  return;
2327  insertItem(index, QIcon(), QString());
2328  QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));
2329 }
2330 
2338 {
2339  Q_D(QComboBox);
2340  if (index < 0 || index >= count())
2341  return;
2342  d->model->removeRows(index, 1, d->root);
2343 }
2344 
2349 {
2350  Q_D(const QComboBox);
2351  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2352  if (item.isValid()) {
2353  d->model->setData(item, text, Qt::EditRole);
2354  }
2355 }
2356 
2360 void QComboBox::setItemIcon(int index, const QIcon &icon)
2361 {
2362  Q_D(const QComboBox);
2363  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2364  if (item.isValid()) {
2365  d->model->setData(item, icon, Qt::DecorationRole);
2366  }
2367 }
2368 
2373 void QComboBox::setItemData(int index, const QVariant &value, int role)
2374 {
2375  Q_D(const QComboBox);
2376  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2377  if (item.isValid()) {
2378  d->model->setData(item, value, role);
2379  }
2380 }
2381 
2386 {
2387  Q_D(const QComboBox);
2388  return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();
2389 }
2390 
2401 {
2402  Q_D(QComboBox);
2403  if (!itemView) {
2404  qWarning("QComboBox::setView: cannot set a 0 view");
2405  return;
2406  }
2407 
2408  if (itemView->model() != d->model)
2409  itemView->setModel(d->model);
2410  d->viewContainer()->setItemView(itemView);
2411 }
2412 
2417 {
2418  Q_D(const QComboBox);
2419  return d->recomputeSizeHint(d->minimumSizeHint);
2420 }
2421 
2433 {
2434  Q_D(const QComboBox);
2435  return d->recomputeSizeHint(d->sizeHint);
2436 }
2437 
2448 {
2449  Q_D(QComboBox);
2450  if (count() <= 0)
2451  return;
2452 
2453 #ifdef QT_KEYPAD_NAVIGATION
2454 #ifndef QT_NO_COMPLETER
2455  if (QApplication::keypadNavigationEnabled() && d->completer) {
2456  // editable combo box is line edit plus completer
2457  setEditFocus(true);
2458  d->completer->complete(); // show popup
2459  return;
2460  }
2461 #endif
2462 #endif
2463 
2464  QStyle * const style = this->style();
2465 
2466  // set current item and select it
2467  view()->selectionModel()->setCurrentIndex(d->currentIndex,
2469  QComboBoxPrivateContainer* container = d->viewContainer();
2471  initStyleOption(&opt);
2472  QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
2474 #ifndef Q_WS_S60
2475  QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
2476 #else
2477  QRect screen = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect());
2478 #endif
2479 
2480  QPoint below = mapToGlobal(listRect.bottomLeft());
2481  int belowHeight = screen.bottom() - below.y();
2482  QPoint above = mapToGlobal(listRect.topLeft());
2483  int aboveHeight = above.y() - screen.y();
2484  bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);
2485 
2486  const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
2487  {
2488  int listHeight = 0;
2489  int count = 0;
2490  QStack<QModelIndex> toCheck;
2491  toCheck.push(view()->rootIndex());
2492 #ifndef QT_NO_TREEVIEW
2493  QTreeView *treeView = qobject_cast<QTreeView*>(view());
2494  if (treeView && treeView->header() && !treeView->header()->isHidden())
2495  listHeight += treeView->header()->height();
2496 #endif
2497  while (!toCheck.isEmpty()) {
2498  QModelIndex parent = toCheck.pop();
2499  for (int i = 0; i < d->model->rowCount(parent); ++i) {
2500  QModelIndex idx = d->model->index(i, d->modelColumn, parent);
2501  if (!idx.isValid())
2502  continue;
2503  listHeight += view()->visualRect(idx).height() + container->spacing();
2504 #ifndef QT_NO_TREEVIEW
2505  if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
2506  toCheck.push(idx);
2507 #endif
2508  ++count;
2509  if (!usePopup && count >= d->maxVisibleItems) {
2510  toCheck.clear();
2511  break;
2512  }
2513  }
2514  }
2515  listRect.setHeight(listHeight);
2516  }
2517 
2518  {
2519  // add the spacing for the grid on the top and the bottom;
2520  int heightMargin = 2*container->spacing();
2521 
2522  // add the frame of the container
2523  int marginTop, marginBottom;
2524  container->getContentsMargins(0, &marginTop, 0, &marginBottom);
2525  heightMargin += marginTop + marginBottom;
2526 
2527  //add the frame of the view
2528  view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
2529  marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
2530  marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
2531  heightMargin += marginTop + marginBottom;
2532 
2533  listRect.setHeight(listRect.height() + heightMargin);
2534  }
2535 
2536  // Add space for margin at top and bottom if the style wants it.
2537  if (usePopup)
2538  listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
2539 
2540  // Make sure the popup is wide enough to display its contents.
2541  if (usePopup) {
2542  const int diff = d->computeWidthHint() - width();
2543  if (diff > 0)
2544  listRect.setWidth(listRect.width() + diff);
2545  }
2546 
2547  //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
2548  container->layout()->activate();
2549  //takes account of the minimum/maximum size of the container
2550  listRect.setSize( listRect.size().expandedTo(container->minimumSize())
2551  .boundedTo(container->maximumSize()));
2552 
2553  // make sure the widget fits on screen
2554  if (boundToScreen) {
2555  if (listRect.width() > screen.width() )
2556  listRect.setWidth(screen.width());
2557  if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
2558  below.setX(screen.x() + screen.width() - listRect.width());
2559  above.setX(screen.x() + screen.width() - listRect.width());
2560  }
2561  if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
2562  below.setX(screen.x());
2563  above.setX(screen.x());
2564  }
2565  }
2566 
2567  if (usePopup) {
2568  // Position horizontally.
2569  listRect.moveLeft(above.x());
2570 
2571 #ifndef Q_WS_S60
2572  // Position vertically so the curently selected item lines up
2573  // with the combo box.
2574  const QRect currentItemRect = view()->visualRect(view()->currentIndex());
2575  const int offset = listRect.top() - currentItemRect.top();
2576  listRect.moveTop(above.y() + offset - listRect.top());
2577 #endif
2578 
2579 
2580  // Clamp the listRect height and vertical position so we don't expand outside the
2581  // available screen geometry.This may override the vertical position, but it is more
2582  // important to show as much as possible of the popup.
2583  const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
2584  listRect.setHeight(height);
2585 
2586  if (boundToScreen) {
2587  if (listRect.top() < screen.top())
2588  listRect.moveTop(screen.top());
2589  if (listRect.bottom() > screen.bottom())
2590  listRect.moveBottom(screen.bottom());
2591  }
2592 #ifdef Q_WS_S60
2593  if (screen.width() < screen.height()) {
2594  // in portait, menu should be positioned above softkeys
2595  listRect.moveBottom(screen.bottom());
2596  } else {
2597  TRect staConTopRect = TRect();
2598  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
2599  listRect.setWidth(screen.height());
2600  //by default popup is centered on screen in landscape
2601  listRect.moveCenter(screen.center());
2602  if (staConTopRect.IsEmpty() && AknLayoutUtils::CbaLocation() != AknLayoutUtils::EAknCbaLocationBottom) {
2603  // landscape without stacon, menu should be at the right
2604  (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
2605  listRect.setLeft(screen.left());
2606  }
2607  }
2608 #endif
2609  } else if (!boundToScreen || listRect.height() <= belowHeight) {
2610  listRect.moveTopLeft(below);
2611  } else if (listRect.height() <= aboveHeight) {
2612  listRect.moveBottomLeft(above);
2613  } else if (belowHeight >= aboveHeight) {
2614  listRect.setHeight(belowHeight);
2615  listRect.moveTopLeft(below);
2616  } else {
2617  listRect.setHeight(aboveHeight);
2618  listRect.moveBottomLeft(above);
2619  }
2620 
2621 #ifndef QT_NO_IM
2622  if (QInputContext *qic = inputContext())
2623  qic->reset();
2624 #endif
2625  QScrollBar *sb = view()->horizontalScrollBar();
2627  bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)
2628  && sb->minimum() < sb->maximum();
2629  if (needHorizontalScrollBar) {
2630  listRect.adjust(0, 0, 0, sb->height());
2631  }
2632  container->setGeometry(listRect);
2633 
2634 #ifndef Q_WS_MAC
2635  const bool updatesEnabled = container->updatesEnabled();
2636 #endif
2637 
2638 #if defined(Q_WS_WIN) && !defined(QT_NO_EFFECTS)
2639  bool scrollDown = (listRect.topLeft() == below);
2642  qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
2643 #endif
2644 
2645 // Don't disable updates on Mac OS X. Windows are displayed immediately on this platform,
2646 // which means that the window will be visible before the call to container->show() returns.
2647 // If updates are disabled at this point we'll miss our chance at painting the popup
2648 // menu before it's shown, causing flicker since the window then displays the standard gray
2649 // background.
2650 #ifndef Q_WS_MAC
2651  container->setUpdatesEnabled(false);
2652 #endif
2653 
2654  container->raise();
2655  container->show();
2656  container->updateScrollers();
2657  view()->setFocus();
2658 
2659  view()->scrollTo(view()->currentIndex(),
2660  style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)
2663 
2664 #ifndef Q_WS_MAC
2665  container->setUpdatesEnabled(updatesEnabled);
2666 #endif
2667 
2668  container->update();
2669 #ifdef QT_KEYPAD_NAVIGATION
2670  if (QApplication::keypadNavigationEnabled())
2671  view()->setEditFocus(true);
2672 #endif
2673 }
2674 
2686 {
2687  Q_D(QComboBox);
2688  if (d->container && d->container->isVisible()) {
2689 #if !defined(QT_NO_EFFECTS)
2690  d->model->blockSignals(true);
2691  d->container->itemView()->blockSignals(true);
2692  d->container->blockSignals(true);
2693  // Flash selected/triggered item (if any).
2695  QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;
2696  if (selectionModel && selectionModel->hasSelection()) {
2697  QEventLoop eventLoop;
2698  const QItemSelection selection = selectionModel->selection();
2699 
2700  // Deselect item and wait 60 ms.
2701  selectionModel->select(selection, QItemSelectionModel::Toggle);
2702  QTimer::singleShot(60, &eventLoop, SLOT(quit()));
2703  eventLoop.exec();
2704 
2705  // Select item and wait 20 ms.
2706  selectionModel->select(selection, QItemSelectionModel::Toggle);
2707  QTimer::singleShot(20, &eventLoop, SLOT(quit()));
2708  eventLoop.exec();
2709  }
2710  }
2711 
2712  // Fade out.
2713  bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide);
2714  if (needFade) {
2715 #if defined(Q_WS_MAC)
2716  macWindowFade(qt_mac_window_for(d->container));
2717 #endif // Q_WS_MAC
2718  // Other platform implementations welcome :-)
2719  }
2720  d->model->blockSignals(false);
2721  d->container->itemView()->blockSignals(false);
2722  d->container->blockSignals(false);
2723 
2724  if (!needFade)
2725 #endif // QT_NO_EFFECTS
2726  // Fade should implicitly hide as well ;-)
2727  d->container->hide();
2728  }
2729 #ifdef QT_KEYPAD_NAVIGATION
2730  if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus())
2731  setEditFocus(true);
2732 #endif
2733  d->_q_resetButton();
2734 }
2735 
2743 {
2744  Q_D(QComboBox);
2745  d->model->removeRows(0, d->model->rowCount(d->root), d->root);
2746 #ifndef QT_NO_ACCESSIBILITY
2748 #endif
2749 }
2750 
2764 {
2765  Q_D(QComboBox);
2766  if (d->lineEdit)
2767  d->lineEdit->clear();
2768 #ifndef QT_NO_ACCESSIBILITY
2770 #endif
2771 }
2772 
2777 {
2778  Q_D(QComboBox);
2779  if (d->lineEdit)
2780  d->lineEdit->setText(text);
2781 #ifndef QT_NO_ACCESSIBILITY
2783 #endif
2784 }
2785 
2790 {
2791  Q_D(QComboBox);
2792  update();
2793  if (d->lineEdit) {
2794  d->lineEdit->event(e);
2795 #ifndef QT_NO_COMPLETER
2796  if (d->lineEdit->completer())
2797  d->lineEdit->completer()->setWidget(this);
2798 #endif
2799  }
2800 }
2801 
2806 {
2807  Q_D(QComboBox);
2808  update();
2809  if (d->lineEdit)
2810  d->lineEdit->event(e);
2811 }
2812 
2815 {
2816  Q_D(QComboBox);
2817  switch (e->type()) {
2818  case QEvent::StyleChange:
2819  d->updateDelegate();
2820 #ifdef Q_WS_MAC
2821  case QEvent::MacSizeChange:
2822 #endif
2823  d->sizeHint = QSize(); // invalidate size hint
2824  d->minimumSizeHint = QSize();
2825  d->updateLayoutDirection();
2826  if (d->lineEdit)
2827  d->updateLineEditGeometry();
2828  d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
2829 
2830 #ifdef Q_WS_S60
2831  if (d->container) {
2833  initStyleOption(&opt);
2834 
2835  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
2836  QRect screen = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect());
2837 
2838  QRect listRect(style()->subControlRect(QStyle::CC_ComboBox, &opt,
2840  listRect.setHeight(qMin(screen.height(), screen.width()));
2841 
2842  if (screen.width() < screen.height()) {
2843  // in portait, menu should be positioned above softkeys
2844  listRect.moveBottom(screen.bottom());
2845  } else {
2846  TRect staConTopRect = TRect();
2847  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
2848  listRect.setWidth(listRect.height());
2849  //by default popup is centered on screen in landscape
2850  listRect.moveCenter(screen.center());
2851  if (staConTopRect.IsEmpty() && AknLayoutUtils::CbaLocation() != AknLayoutUtils::EAknCbaLocationBottom) {
2852  // landscape without stacon, menu should be at the right
2853  (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
2854  listRect.setLeft(screen.left());
2855  }
2856  }
2857 
2858  d->container->setGeometry(listRect);
2859  }
2860  }
2861 #endif
2862 
2863  // ### need to update scrollers etc. as well here
2864  break;
2865  case QEvent::EnabledChange:
2866  if (!isEnabled())
2867  hidePopup();
2868  break;
2869  case QEvent::PaletteChange: {
2870  d->updateViewContainerPaletteAndOpacity();
2871  break;
2872  }
2873  case QEvent::FontChange:
2874  d->sizeHint = QSize(); // invalidate size hint
2875  d->viewContainer()->setFont(font());
2876  if (d->lineEdit)
2877  d->updateLineEditGeometry();
2878  break;
2879  default:
2880  break;
2881  }
2883 }
2884 
2889 {
2890  Q_D(QComboBox);
2891 #ifdef Q_WS_S60
2892  if (d->viewContainer() && d->viewContainer()->isVisible())
2893  showPopup();
2894 #endif
2895  d->updateLineEditGeometry();
2896 }
2897 
2902 {
2903  QStylePainter painter(this);
2904  painter.setPen(palette().color(QPalette::Text));
2905 
2906  // draw the combobox frame, focusrect and selected etc.
2908  initStyleOption(&opt);
2910 
2911  // draw the icon and text
2912  painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
2913 }
2914 
2919 {
2920  Q_D(QComboBox);
2921  if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
2922  d->sizeHint = QSize();
2923  updateGeometry();
2924  }
2925  d->shownOnce = true;
2926  QWidget::showEvent(e);
2927 }
2928 
2933 {
2934  hidePopup();
2935 }
2936 
2941 {
2942  Q_D(QComboBox);
2943  switch(event->type()) {
2946  d->updateLayoutDirection();
2947  d->updateLineEditGeometry();
2948  break;
2949  case QEvent::HoverEnter:
2950  case QEvent::HoverLeave:
2951  case QEvent::HoverMove:
2952  if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
2953  d->updateHoverControl(he->pos());
2954  break;
2956  if (d->lineEdit)
2957  return d->lineEdit->event(event);
2958  break;
2959 #ifdef QT_KEYPAD_NAVIGATION
2960  case QEvent::EnterEditFocus:
2961  if (!d->lineEdit)
2962  setEditFocus(false); // We never want edit focus if we are not editable
2963  else
2964  d->lineEdit->event(event); //so cursor starts
2965  break;
2966  case QEvent::LeaveEditFocus:
2967  if (d->lineEdit)
2968  d->lineEdit->event(event); //so cursor stops
2969  break;
2970 #endif
2971  default:
2972  break;
2973  }
2974  return QWidget::event(event);
2975 }
2976 
2981 {
2982  Q_D(QComboBox);
2984  initStyleOption(&opt);
2986  this);
2987  if (e->button() == Qt::LeftButton && (sc == QStyle::SC_ComboBoxArrow || !isEditable())
2988  && !d->viewContainer()->isVisible()) {
2989  if (sc == QStyle::SC_ComboBoxArrow)
2990  d->updateArrow(QStyle::State_Sunken);
2991 #ifdef QT_KEYPAD_NAVIGATION
2992  //if the container already exists, then d->viewContainer() is safe to call
2993  if (d->container) {
2994 #endif
2995  // We've restricted the next couple of lines, because by not calling
2996  // viewContainer(), we avoid creating the QComboBoxPrivateContainer.
2997  d->viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval());
2998  d->viewContainer()->initialClickPosition = mapToGlobal(e->pos());
2999 #ifdef QT_KEYPAD_NAVIGATION
3000  }
3001 #endif
3002  showPopup();
3003  } else {
3004 #ifdef QT_KEYPAD_NAVIGATION
3005  if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && d->lineEdit) {
3006  d->lineEdit->event(e); //so lineedit can move cursor, etc
3007  return;
3008  }
3009 #endif
3011  }
3012 }
3013 
3018 {
3019  Q_D(QComboBox);
3020  Q_UNUSED(e);
3021  d->updateArrow(QStyle::State_None);
3022 }
3023 
3028 {
3029  Q_D(QComboBox);
3030 
3031 #ifndef QT_NO_COMPLETER
3032  if (d->lineEdit
3033  && d->lineEdit->completer()
3034  && d->lineEdit->completer()->popup()
3035  && d->lineEdit->completer()->popup()->isVisible()) {
3036  // provide same autocompletion support as line edit
3037  d->lineEdit->event(e);
3038  return;
3039  }
3040 #endif
3041 
3042  enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};
3043 
3044  Move move = NoMove;
3045  int newIndex = currentIndex();
3046  switch (e->key()) {
3047  case Qt::Key_Up:
3048  if (e->modifiers() & Qt::ControlModifier)
3049  break; // pass to line edit for auto completion
3050  case Qt::Key_PageUp:
3051 #ifdef QT_KEYPAD_NAVIGATION
3052  if (QApplication::keypadNavigationEnabled())
3053  e->ignore();
3054  else
3055 #endif
3056  move = MoveUp;
3057  break;
3058  case Qt::Key_Down:
3059  if (e->modifiers() & Qt::AltModifier) {
3060  showPopup();
3061  return;
3062  } else if (e->modifiers() & Qt::ControlModifier)
3063  break; // pass to line edit for auto completion
3064  // fall through
3065  case Qt::Key_PageDown:
3066 #ifdef QT_KEYPAD_NAVIGATION
3067  if (QApplication::keypadNavigationEnabled())
3068  e->ignore();
3069  else
3070 #endif
3071  move = MoveDown;
3072  break;
3073  case Qt::Key_Home:
3074  if (!d->lineEdit)
3075  move = MoveFirst;
3076  break;
3077  case Qt::Key_End:
3078  if (!d->lineEdit)
3079  move = MoveLast;
3080  break;
3081  case Qt::Key_F4:
3082  if (!e->modifiers()) {
3083  showPopup();
3084  return;
3085  }
3086  break;
3087  case Qt::Key_Space:
3088  if (!d->lineEdit) {
3089  showPopup();
3090  return;
3091  }
3092  case Qt::Key_Enter:
3093  case Qt::Key_Return:
3094  case Qt::Key_Escape:
3095  if (!d->lineEdit)
3096  e->ignore();
3097  break;
3098 #ifdef QT_KEYPAD_NAVIGATION
3099  case Qt::Key_Select:
3100  if (QApplication::keypadNavigationEnabled()
3101  && (!hasEditFocus() || !d->lineEdit)) {
3102  showPopup();
3103  return;
3104  }
3105  break;
3106  case Qt::Key_Left:
3107  case Qt::Key_Right:
3108  if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
3109  e->ignore();
3110  break;
3111  case Qt::Key_Back:
3112  if (QApplication::keypadNavigationEnabled()) {
3113  if (!hasEditFocus() || !d->lineEdit)
3114  e->ignore();
3115  } else {
3116  e->ignore(); // let the surounding dialog have it
3117  }
3118  break;
3119 #endif
3120  default:
3121  if (!d->lineEdit) {
3122  if (!e->text().isEmpty())
3123  d->keyboardSearchString(e->text());
3124  else
3125  e->ignore();
3126  }
3127  }
3128 
3129  if (move != NoMove) {
3130  e->accept();
3131  switch (move) {
3132  case MoveFirst:
3133  newIndex = -1;
3134  case MoveDown:
3135  newIndex++;
3136  while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3137  newIndex++;
3138  break;
3139  case MoveLast:
3140  newIndex = count();
3141  case MoveUp:
3142  newIndex--;
3143  while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3144  newIndex--;
3145  break;
3146  default:
3147  e->ignore();
3148  break;
3149  }
3150 
3151  if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
3152  setCurrentIndex(newIndex);
3153  d->emitActivated(d->currentIndex);
3154  }
3155  } else if (d->lineEdit) {
3156  d->lineEdit->event(e);
3157  }
3158 }
3159 
3160 
3165 {
3166  Q_D(QComboBox);
3167  if (d->lineEdit)
3168  d->lineEdit->event(e);
3169 }
3170 
3174 #ifndef QT_NO_WHEELEVENT
3176 {
3177  Q_D(QComboBox);
3178  if (!d->viewContainer()->isVisible()) {
3179  int newIndex = currentIndex();
3180 
3181  if (e->delta() > 0) {
3182  newIndex--;
3183  while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3184  newIndex--;
3185  } else {
3186  newIndex++;
3187  while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3188  newIndex++;
3189  }
3190 
3191  if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
3192  setCurrentIndex(newIndex);
3193  d->emitActivated(d->currentIndex);
3194  }
3195  e->accept();
3196  }
3197 }
3198 #endif
3199 
3200 #ifndef QT_NO_CONTEXTMENU
3201 
3205 {
3206  Q_D(QComboBox);
3207  if (d->lineEdit) {
3208  Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();
3209  d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
3210  d->lineEdit->event(e);
3211  d->lineEdit->setContextMenuPolicy(p);
3212  }
3213 }
3214 #endif // QT_NO_CONTEXTMENU
3215 
3217 {
3218  // use keyboardSearch from the listView so we do not duplicate code
3219  QAbstractItemView *view = viewContainer()->itemView();
3221  int currentRow = view->currentIndex().row();
3222  view->keyboardSearch(text);
3223  if (currentRow != view->currentIndex().row()) {
3224  setCurrentIndex(view->currentIndex());
3225  emitActivated(currentIndex);
3226  }
3227 }
3228 
3230 {
3231  Q_Q(QComboBox);
3232 
3234  sizeHint = QSize();
3235  adjustComboBoxSize();
3236  q->updateGeometry();
3237  }
3238 }
3239 
3244 {
3245  Q_D(QComboBox);
3246  if (d->lineEdit) {
3247  d->lineEdit->event(e);
3248  } else {
3249  if (!e->commitString().isEmpty())
3250  d->keyboardSearchString(e->commitString());
3251  else
3252  e->ignore();
3253  }
3254 }
3255 
3260 {
3261  Q_D(const QComboBox);
3262  if (d->lineEdit)
3263  return d->lineEdit->inputMethodQuery(query);
3264  return QWidget::inputMethodQuery(query);
3265 }
3266 
3459 {
3460  Q_D(const QComboBox);
3461  return d->frame;
3462 }
3463 
3464 
3465 void QComboBox::setFrame(bool enable)
3466 {
3467  Q_D(QComboBox);
3468  d->frame = enable;
3469  update();
3470  updateGeometry();
3471 }
3472 
3486 int QComboBox::modelColumn() const
3487 {
3488  Q_D(const QComboBox);
3489  return d->modelColumn;
3490 }
3491 
3492 void QComboBox::setModelColumn(int visibleColumn)
3493 {
3494  Q_D(QComboBox);
3495  d->modelColumn = visibleColumn;
3496  QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());
3497  if (lv)
3498  lv->setModelColumn(visibleColumn);
3499 #ifndef QT_NO_COMPLETER
3500  if (d->lineEdit && d->lineEdit->completer()
3501  && d->lineEdit->completer() == d->completer)
3502  d->lineEdit->completer()->setCompletionColumn(visibleColumn);
3503 #endif
3504  setCurrentIndex(currentIndex()); //update the text to the text of the new column;
3505 }
3506 
3554 
3555 #include "moc_qcombobox.cpp"
3556 
3557 #endif // QT_NO_COMBOBOX
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void focusOutEvent(QFocusEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2805
void scrollItemView(int action)
Definition: qcombobox.cpp:459
QPoint pos() const
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
double d
Definition: qnumeric_p.h:62
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
int findData(const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Returns the index of the item containing the given data for the given role; otherwise returns -1...
Definition: qcombobox.cpp:1572
QLineEdit * lineEdit
Definition: qcombobox_p.h:386
void setSingleShot(bool singleShot)
Definition: qtimer.h:108
bool updateHoverControl(const QPoint &pos)
Definition: qcombobox.cpp:240
void keyboardSearchString(const QString &text)
Definition: qcombobox.cpp:3216
QString itemText(const QModelIndex &index) const
Definition: qcombobox.cpp:1312
bool event(QEvent *event)
Reimplemented Function
Definition: qcombobox.cpp:2940
QAbstractItemModel * model
Definition: qcombobox_p.h:385
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void showEvent(QShowEvent *e)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qcombobox.cpp:702
void focusInEvent(QFocusEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2789
The QAbstractItemDelegate class is used to display and edit data items from a model.
int row() const
Returns the row this persistent model index refers to.
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
static QAbstractItemModel * staticEmptyModel()
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QLayoutItem * itemAt(int) const
Reimplemented Function
Definition: qboxlayout.cpp:778
void setInsertPolicy(InsertPolicy policy)
Definition: qcombobox.cpp:1603
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void keyPressEvent(QKeyEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:3027
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
static QString standardSoftKeyText(StandardSoftKey standardKey)
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
The QBoxLayout class lines up child widgets horizontally or vertically.
Definition: qboxlayout.h:60
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for the popup list view.
Definition: qcombobox.cpp:1954
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
QSize iconSize
the icon size for the current item of the combo box
Definition: qstyleoption.h:807
QSize size() const
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QString currentText() const
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget&#39;s style to draw a control element ce specified by QStyleOption option.
Definition: qstylepainter.h:87
bool frame
whether the combo box has a frame
Definition: qstyleoption.h:804
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
int qCeil(qreal v)
Definition: qmath.h:63
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
SizeAdjustPolicy sizeAdjustPolicy() const
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
void keyReleaseEvent(QKeyEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:3164
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
int minimum() const
QIcon icon
the icon for the menu item
Definition: qstyleoption.h:451
void setSizeAdjustPolicy(SizeAdjustPolicy policy)
Definition: qcombobox.cpp:1628
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
bool isVisible() const
Definition: qwidget.h:1005
bool autoCompletion() const
static QSize globalStrut()
void setMinimumContentsLength(int characters)
Definition: qcombobox.cpp:1660
void showEvent(QShowEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2918
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QFont font
the font used for the menu item text
Definition: qstyleoption.h:454
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString currentText
the text for the current item of the combo box
Definition: qstyleoption.h:805
void inputMethodEvent(QInputMethodEvent *)
Reimplemented Function
Definition: qcombobox.cpp:3243
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
void setIconSize(const QSize &size)
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
void paintEvent(QPaintEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2901
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setEditTriggers(EditTriggers triggers)
void mousePressEvent(QMouseEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2980
SizeAdjustPolicy
This enum specifies how the size hint of the QComboBox should adjust when new content is added or con...
Definition: qcombobox.h:144
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
Definition: qlineedit.cpp:940
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
void _q_itemSelected(const QModelIndex &item)
Definition: qcombobox.cpp:1270
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void insertSpacing(int index, int size)
Inserts a non-stretchable space (a QSpacerItem) at position index, with size size.
Definition: qboxlayout.cpp:929
void deselect()
Deselects any selected text.
Definition: qlineedit.cpp:1417
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
void setModelColumn(int visibleColumn)
Definition: qcombobox.cpp:3492
void triggerAction(SliderAction action)
Triggers a slider action.
QIcon currentIcon
the icon for the current item of the combo box
Definition: qstyleoption.h:806
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition: qlayout.cpp:1249
bool updatesEnabled() const
Qt::ScrollBarPolicy horizontalScrollBarPolicy() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
void setItemText(int index, const QString &text)
Sets the text for the item on the given index in the combobox.
Definition: qcombobox.cpp:2348
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QPalette palette()
Returns the application palette.
QGraphicsProxyWidget * graphicsProxyWidget() const
Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns ...
Definition: qwidget.cpp:12939
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
The QStandardItemModel class provides a generic model for storing custom data.
void setItemData(int index, const QVariant &value, int role=Qt::UserRole)
Sets the data role for the item on the given index in the combobox to the specified value...
Definition: qcombobox.cpp:2373
bool editable
whether or not the combobox is editable or not
Definition: qstyleoption.h:802
friend OSWindowRef qt_mac_window_for(const QWidget *w)
Definition: qwidget_mac.mm:484
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
Definition: qtreeview.cpp:859
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QAbstractItemView * itemView() const
Definition: qcombobox.cpp:514
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QSize recomputeSizeHint(QSize &sh) const
Definition: qcombobox.cpp:296
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
bool hasFocus() const
Definition: qwidget.cpp:6583
void _q_emitHighlighted(const QModelIndex &)
Definition: qcombobox.cpp:1292
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void setLineWidth(int)
Definition: qframe.cpp:368
void itemSelected(const QModelIndex &)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define X11
Definition: qt_x11_p.h:724
void adjustComboBoxSize()
Definition: qcombobox.cpp:351
void setUpdatesEnabled(bool enable)
Definition: qwidget.cpp:7670
#define Q_D(Class)
Definition: qglobal.h:2482
InsertPolicy
This enum specifies what the QComboBox should do when a new string is entered by the user...
Definition: qcombobox.h:119
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by the popup list view.
Definition: qcombobox.cpp:1937
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
int height() const
void insertSeparator(int index)
Inserts a separator item into the combobox at the given index.
Definition: qcombobox.cpp:2320
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
static bool isSeparator(const QModelIndex &index)
Definition: qcombobox_p.h:301
void setFrame(bool)
Definition: qcombobox.cpp:3465
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
QString text
the text for the menu item
Definition: qstyleoption.h:450
QCompleter * completer() const
Returns the current QCompleter that provides completions.
Definition: qlineedit.cpp:686
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void setLayoutDirection(Qt::LayoutDirection direction)
Definition: qwidget.cpp:5199
void leaveEvent(QEvent *e)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qcombobox.cpp:398
QSize minimumSizeHint() const
Reimplemented Function
Definition: qcombobox.cpp:2416
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString itemText(int index) const
Returns the text for the given index in the combobox.
Definition: qcombobox.cpp:2161
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void clearEditText()
Clears the contents of the line edit used for editing in the combobox.
Definition: qcombobox.cpp:2763
QStyle * style() const
Definition: qwidget.cpp:2742
virtual QSpacerItem * spacerItem()
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned.
QVariant itemData(int index, int role=Qt::UserRole) const
Returns the data for the given role in the given index in the combobox, or QVariant::Invalid if there...
Definition: qcombobox.cpp:2182
void activated(int index)
This signal is sent when the user chooses an item in the combobox.
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void setValidator(const QValidator *v)
Sets the validator to use instead of the current validator.
Definition: qcombobox.cpp:1871
void resizeEvent(QResizeEvent *e)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qcombobox.cpp:382
void invalidate()
Resets cached information.
Definition: qboxlayout.cpp:759
bool editable
whether the combo box can be edited by the user
Definition: qcombobox.h:68
void setMaxCount(int max)
Definition: qcombobox.cpp:1397
int count() const
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QVariant inputMethodQuery(Qt::InputMethodQuery) const
Reimplemented Function
Definition: qcombobox.cpp:3259
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
QComboBoxPrivateScroller * top
Definition: qcombobox_p.h:257
QStyle::SubControl hoverControl
Definition: qcombobox_p.h:404
QWidget * viewport() const
Returns the viewport widget.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
int minimumContentsLength() const
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
QRect popupGeometry(int screen=-1) const
Definition: qcombobox.cpp:226
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
QSize iconSize() const
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void updateLayoutDirection()
Definition: qcombobox.cpp:356
int modelColumn() const
QComboBoxPrivateContainer * container
Definition: qcombobox_p.h:387
void mousePressEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qcombobox.cpp:720
int width() const
Returns the width.
Definition: qsize.h:126
Qt::CaseSensitivity caseSensitivity
the case sensitivity of the matching
Definition: qcompleter.h:73
static QAction * createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget)
Creates a QAction and registers the &#39;triggered&#39; signal to send the given key event to actionWidget as...
QStyle::StateFlag arrowState
Definition: qcombobox_p.h:403
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void changeEvent(QEvent *e)
This event handler can be reimplemented to handle state changes.
Definition: qcombobox.cpp:625
QComboBox(QWidget *parent=0)
Constructs a combobox with the given parent, using the default model QStandardItemModel.
Definition: qcombobox.cpp:870
qreal windowOpacity() const
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
int value() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
void updateLineEditGeometry()
Definition: qcombobox.cpp:1168
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
void emitActivated(const QModelIndex &)
Definition: qcombobox.cpp:1282
Qt::CaseSensitivity autoCompletionCaseSensitivity() const
void contextMenuEvent(QContextMenuEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:3204
void updateDelegate(bool force=false)
Definition: qcombobox.cpp:1736
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Definition: qcombobox.cpp:1032
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
void setEditable(bool editable)
Definition: qcombobox.cpp:1759
ContextMenuPolicy
Definition: qnamespace.h:1533
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
The QSpacerItem class provides blank space in a layout.
Definition: qlayoutitem.h:96
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
Scroll widget w in time ms.
Definition: qeffects.cpp:562
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
void insertWidget(int index, QWidget *widget, int stretch=0, Qt::Alignment alignment=0)
Inserts widget at position index, with stretch factor stretch and alignment alignment.
int maxCount() const
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
int count() const
Reimplemented Function
Definition: qboxlayout.cpp:769
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index...
Definition: qcombobox.h:329
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity)
Use setCompleter() and QCompleter::setCaseSensitivity() instead.
Definition: qcombobox.cpp:1521
QComboBoxPrivateScroller * bottom
Definition: qcombobox_p.h:258
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
int row() const
Returns the row this model index refers to.
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition: qwidget.cpp:8488
bool checked
whether the menu item is checked or not
Definition: qstyleoption.h:447
void setView(QAbstractItemView *itemView)
Sets the view to be used in the combobox popup to the given itemView.
Definition: qcombobox.cpp:2400
const char * name
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition: qpoint.cpp:489
const QPalette & palette() const
LayoutDirection
Definition: qnamespace.h:1580
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QWidgetData * data
Definition: qwidget.h:815
void _q_editingFinished()
Definition: qcombobox.cpp:1199
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
void hideEvent(QHideEvent *e)
This event handler can be reimplemented in a subclass to receive widget hide events.
Definition: qcombobox.cpp:707
const char * styleHint(const QFontDef &request)
QComboBoxPrivateContainer * viewContainer()
Definition: qcombobox.cpp:1005
void hideEvent(QHideEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2932
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
Q_CORE_EXPORT void qWarning(const char *,...)
int delta() const
Returns the distance that the wheel is rotated, in eighths of a degree.
Definition: qevent.h:150
void setCompleter(QCompleter *c)
Definition: qcombobox.cpp:1903
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
static void setSeparator(QAbstractItemModel *model, const QModelIndex &index)
Definition: qcombobox_p.h:304
static Bigint * diff(Bigint *a, Bigint *b)
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition: qtimer.h:69
FontHash * qt_app_fonts_hash()
void _q_returnPressed()
Definition: qcombobox.cpp:1213
QModelIndex currentIndex() const
Returns the model index of the current item.
void updateArrow(QStyle::StateFlag state)
Definition: qcombobox.cpp:196
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
void _q_updateIndexBeforeChange()
Definition: qcombobox.cpp:1078
QAbstractItemModel * model() const
Returns the model used by the combobox.
Definition: qcombobox.cpp:1968
quint16 values[128]
QStyle::SubControl newHoverControl(const QPoint &pos)
Definition: qcombobox.cpp:255
int maxVisibleItems() const
void show()
Shows the widget and its child widgets.
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void _q_modelDestroyed()
Definition: qcombobox.cpp:219
QAbstractItemView * view
Definition: qcombobox_p.h:256
#define QT_CATCH(A)
Definition: qglobal.h:1537
QComboBox::SizeAdjustPolicy sizeAdjustPolicy
Definition: qcombobox_p.h:389
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
void setModelColumn(int column)
Definition: qlistview.cpp:1586
The QTableView class provides a default model/view implementation of a table view.
Definition: qtableview.h:58
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QRect rect() const
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
void setLineEdit(QLineEdit *edit)
Sets the line edit to use instead of the current line edit widget.
Definition: qcombobox.cpp:1797
bool isEnabled() const
Definition: qwidget.h:948
void hide()
Hides the widget.
Definition: qwidget.h:501
void setCurrentIndex(const QModelIndex &index)
Definition: qcombobox.cpp:2109
void editTextChanged(const QString &)
This signal is emitted when the text in the combobox&#39;s line edit widget is changed.
void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:3017
QIcon itemIcon(const QModelIndex &index) const
Definition: qcombobox.cpp:1750
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
The QAbstractItemModel class provides the abstract interface for item model classes.
Qt::MatchFlags matchFlags() const
Definition: qcombobox.cpp:1187
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
Qt::ItemFlags flags() const
Returns the flags for the item referred to by the index.
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
void timerEvent(QTimerEvent *timerEvent)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qcombobox.cpp:370
void setText(const QString &)
Definition: qlineedit.cpp:401
QPersistentModelIndex currentIndex
Definition: qcombobox_p.h:406
InputMethodQuery
Definition: qnamespace.h:1541
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
int spacing() const
Returns the spacing between the items in the view.
Definition: qcombobox.cpp:588
const QValidator * validator() const
Returns the validator that is used to constrain text input for the combobox.
Definition: qcombobox.cpp:1884
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
CaseSensitivity
Definition: qnamespace.h:1451
bool hasSelection() const
Returns true if the selection model contains any selection ranges; otherwise returns false...
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
The QAbstractItemView class provides the basic functionality for item view classes.
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
QSize sizeHint() const
This implementation caches the size hint to avoid resizing when the contents change dynamically...
Definition: qcombobox.cpp:2432
void setAutoCompletion(bool enable)
Use setCompleter() instead.
Definition: qcombobox.cpp:1457
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static bool isEffectEnabled(Qt::UIEffect)
Returns true if effect is enabled; otherwise returns false.
const QRect screenGeometry(int screen=-1) const
The QItemSelection class manages information about selected items in a model.
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
void setDuplicatesEnabled(bool enable)
Definition: qcombobox.cpp:1549
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setModel(QAbstractItemModel *model)
Sets the model to be model.
Definition: qcombobox.cpp:1984
int x() const
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QPersistentModelIndex class is used to locate data in a data model.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
bool eventFilter(QObject *o, QEvent *e)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qcombobox.cpp:643
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
QIcon itemIcon(int index) const
Returns the icon for the given index in the combobox.
Definition: qcombobox.cpp:2171
void mouseReleaseEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qcombobox.cpp:735
InsertPolicy insertPolicy() const
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
void setWidget(QWidget *widget)
Sets the widget for which completion are provided for to widget.
Definition: qcompleter.cpp:989
void removeItem(int index)
Removes the item at the given index from the combobox.
Definition: qcombobox.cpp:2337
void addSpacing(int size)
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout...
virtual void showPopup()
Displays the list of items in the combobox.
Definition: qcombobox.cpp:2447
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
ScrollBarPolicy
Definition: qnamespace.h:1420
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
void setSpacing(int spacing)
Reimplements QLayout::setSpacing().
Definition: qboxlayout.cpp:667
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setItemIcon(int index, const QIcon &icon)
Sets the icon for the item on the given index in the combobox.
Definition: qcombobox.cpp:2360
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int currentIndex() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
~QComboBox()
Destroys the combobox.
Definition: qcombobox.cpp:1325
void setFrameStyle(int)
Sets the frame style to style.
Definition: qframe.cpp:329
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
QSize maximumSize() const
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void clear()
Clears the combobox, removing all items.
Definition: qcombobox.cpp:2742
int height() const
Returns the height.
Definition: qsize.h:129
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
Definition: qnamespace.h:54
QSize minimumSize() const
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QCompleter * completer() const
Returns the completer that is used to auto complete text input for the combobox.
Definition: qcombobox.cpp:1924
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
void _q_rowsInserted(const QModelIndex &parent, int start, int end)
Definition: qcombobox.cpp:1056
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=0) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
bool hasFrame() const
Definition: qcombobox.cpp:3458
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
void setIconSize(const QSize &size)
Definition: qcombobox.cpp:1699
void _q_rowsRemoved(const QModelIndex &parent, int start, int end)
Definition: qcombobox.cpp:1083
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
const QFont & font() const
QStyleOptionMenuItem getStyleOption(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: qcombobox.cpp:115
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void resizeEvent(QResizeEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2888
void _q_emitCurrentIndexChanged(const QModelIndex &index)
Definition: qcombobox.cpp:1302
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for this view and its model to delegate.
#define QT_NO_COMPLETER
void updateViewContainerPaletteAndOpacity()
Definition: qcombobox.cpp:1111
QStyleOptionComboBox comboStyleOption() const
Definition: qcombobox.cpp:744
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QLineEdit * lineEdit() const
Returns the line edit used to edit items in the combobox, or 0 if there is no line edit...
Definition: qcombobox.cpp:1858
virtual void hidePopup()
Hides the list of items in the combobox if it is currently visible and resets the internal state...
Definition: qcombobox.cpp:2685
const QRect availableGeometry(int screen=-1) const
const char * variant
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
The QStandardItem class provides an item for use with the QStandardItemModel class.
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
void selectAll()
Selects all the text (i.e.
Definition: qlineedit.cpp:1405
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
Use the widget&#39;s style to draw a complex control cc specified by the QStyleOptionComplex option...
Definition: qstylepainter.h:92
bool isEditable() const
Definition: qcombobox.cpp:1723
void changeEvent(QEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:2814
bool duplicatesEnabled() const
void setItemView(QAbstractItemView *itemView)
Sets the item view to be used for the combobox popup.
Definition: qcombobox.cpp:522
void insertItems(int index, const QStringList &texts)
Inserts the strings from the list into the combobox as separate items, starting at the index specifie...
Definition: qcombobox.cpp:2269
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
int maximum() const
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
QAbstractItemModel * model() const
Returns the model that this view is presenting.
static const KeyPair *const end
QModelIndex rootModelIndex() const
Returns the root model item index for the items in the combobox.
Definition: qcombobox.cpp:2065
int itemRole() const
Definition: qcombobox.cpp:1317
void stop()
Stops the timer.
Definition: qtimer.cpp:284
void setMargin(int)
Definition: qlayout.cpp:464
int computeWidthHint() const
Definition: qcombobox.cpp:272
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
void setEditText(const QString &text)
Sets the text in the combobox&#39;s text edit.
Definition: qcombobox.cpp:2776
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
static int doubleClickInterval()
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
Sets the item&#39;s data for the given role to the specified value.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool showGrid
whether the grid is shown
Definition: qtableview.h:61
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition: qstyle.h:103
void setMaxVisibleItems(int maxItems)
Definition: qcombobox.cpp:1356
#define QT_TRY
Definition: qglobal.h:1536
void changeSize(int w, int h, QSizePolicy::Policy hData=QSizePolicy::Minimum, QSizePolicy::Policy vData=QSizePolicy::Minimum)
Changes this spacer item to have preferred width w, preferred height h, horizontal size policy hPolic...
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)
Definition: qcombobox.cpp:409
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
void insertRows(int row, const QList< QStandardItem *> &items)
Inserts items at row.
void _q_modelReset()
Definition: qcombobox.cpp:207
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
void setPalette(const QPalette &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4858
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
void setRootModelIndex(const QModelIndex &index)
Sets the root model item index for the items in the combobox.
Definition: qcombobox.cpp:2076
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
#define text
Definition: qobjectdefs.h:80
int column() const
Returns the column this model index refers to.
void wheelEvent(QWheelEvent *e)
Reimplemented Function
Definition: qcombobox.cpp:3175
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
virtual void keyboardSearch(const QString &search)
Moves to and selects the item best matching the string search.
void macWindowFade(void *window, float durationSeconds)
int spacing
the space around the items in the layout
Definition: qlistview.h:66
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60