Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qcombobox.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcombobox.h"
5
6#include <qstylepainter.h>
7#include <qpa/qplatformtheme.h>
8#include <qpa/qplatformmenu.h>
9#include <qlineedit.h>
10#include <qapplication.h>
11#include <qlistview.h>
12#if QT_CONFIG(tableview)
13#include <qtableview.h>
14#endif
15#include <qitemdelegate.h>
16#include <qmap.h>
17#if QT_CONFIG(menu)
18#include <qmenu.h>
19#endif
20#include <qevent.h>
21#include <qlayout.h>
22#include <qscrollbar.h>
23#if QT_CONFIG(treeview)
24#include <qtreeview.h>
25#endif
26#include <qheaderview.h>
27#include <qmath.h>
28#include <qmetaobject.h>
29#if QT_CONFIG(proxymodel)
30#include <qabstractproxymodel.h>
31#endif
32#include <qstylehints.h>
33#include <private/qguiapplication_p.h>
34#include <private/qhighdpiscaling_p.h>
35#include <private/qapplication_p.h>
36#include <private/qcombobox_p.h>
37#include <private/qabstractitemmodel_p.h>
38#include <private/qabstractscrollarea_p.h>
39#include <private/qlineedit_p.h>
40#if QT_CONFIG(completer)
41#include <private/qcompleter_p.h>
42#endif
43#include <qdebug.h>
44#if QT_CONFIG(effects)
45# include <private/qeffects_p.h>
46#endif
47#include <private/qstyle_p.h>
48#if QT_CONFIG(accessibility)
49#include "qaccessible.h"
50#endif
51
53
54using namespace Qt::StringLiterals;
55
58 shownOnce(false),
59 duplicatesEnabled(false),
60 frame(true),
61 inserting(false),
62 hidingPopup(false)
63{
64}
65
67{
68#ifdef Q_OS_MAC
69 cleanupNativePopup();
70#endif
71}
72
73QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,
74 const QModelIndex &index) const
75{
76 QStyleOptionMenuItem menuOption;
77
78 QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));
80 if (value.canConvert<QBrush>()) {
81 resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));
82 resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));
83 resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
84 }
85 menuOption.palette = resolvedpalette;
86 menuOption.state = QStyle::State_None;
87 if (mCombo->window()->isActiveWindow())
88 menuOption.state = QStyle::State_Active;
89 if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
90 menuOption.state |= QStyle::State_Enabled;
91 else
94 menuOption.state |= QStyle::State_Selected;
96 // a valid checkstate means that the model has checkable items
98 if (!checkState.isValid()) {
99 menuOption.checked = mCombo->currentIndex() == index.row();
100 } else {
101 menuOption.checked = qvariant_cast<int>(checkState) == Qt::Checked;
102 menuOption.state |= qvariant_cast<int>(checkState) == Qt::Checked
104 }
107 else
109
111 switch (variant.userType()) {
112 case QMetaType::QIcon:
113 menuOption.icon = qvariant_cast<QIcon>(variant);
114 break;
115 case QMetaType::QColor: {
116 static QPixmap pixmap(option.decorationSize);
117 pixmap.fill(qvariant_cast<QColor>(variant));
118 menuOption.icon = pixmap;
119 break; }
120 default:
121 menuOption.icon = qvariant_cast<QPixmap>(variant);
122 break;
123 }
124 if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
126 qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
127 }
128 menuOption.text = index.model()->data(index, Qt::DisplayRole).toString().replace(u'&', "&&"_L1);
129 menuOption.reservedShortcutWidth = 0;
130 menuOption.maxIconWidth = option.decorationSize.width() + 4;
131 menuOption.menuRect = option.rect;
132 menuOption.rect = option.rect;
133
134 // Make sure fonts set on the model or on the combo box, in
135 // that order, also override the font for the popup menu.
136 QVariant fontRoleData = index.data(Qt::FontRole);
137 if (fontRoleData.isValid()) {
138 menuOption.font = qvariant_cast<QFont>(fontRoleData);
139 } else if (mCombo->testAttribute(Qt::WA_SetFont)
142 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) {
143 menuOption.font = mCombo->font();
144 } else {
145 menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
146 }
147
148 menuOption.fontMetrics = QFontMetrics(menuOption.font);
149
150 return menuOption;
151}
152
154 const QStyleOptionViewItem &option, const QModelIndex &index)
155{
158
159 // make sure that the item is checkable
160 Qt::ItemFlags flags = model->flags(index);
162 || !(flags & Qt::ItemIsEnabled))
163 return false;
164
165 // make sure that we have a check state
167 if (!checkState.isValid())
168 return false;
169
170 // make sure that we have the right event type
171 if ((event->type() == QEvent::MouseButtonRelease)
172 || (event->type() == QEvent::MouseButtonDblClick)
173 || (event->type() == QEvent::MouseButtonPress)) {
174 QMouseEvent *me = static_cast<QMouseEvent*>(event);
175 if (me->button() != Qt::LeftButton)
176 return false;
177
178 if ((event->type() == QEvent::MouseButtonPress)
179 || (event->type() == QEvent::MouseButtonDblClick)) {
180 pressedIndex = index.row();
181 return false;
182 }
183
184 if (index.row() != pressedIndex)
185 return false;
186 pressedIndex = -1;
187
188 } else if (event->type() == QEvent::KeyPress) {
189 if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space
190 && static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select)
191 return false;
192 } else {
193 return false;
194 }
195
196 // we don't support user-tristate items in QComboBox (not implemented in any style)
200}
201
202#if QT_CONFIG(completer)
203void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)
204{
205 Q_Q(QComboBox);
206#if QT_CONFIG(proxymodel)
207 if (index.isValid() && q->completer()) {
208 QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());
209 if (proxy) {
210 const QModelIndex &completerIndex = proxy->mapToSource(index);
211 int row = -1;
212 if (completerIndex.model() == model) {
213 row = completerIndex.row();
214 } else {
215 // if QCompleter uses a proxy model to host widget's one - map again
216 QAbstractProxyModel *completerProxy = qobject_cast<QAbstractProxyModel *>(q->completer()->model());
217 if (completerProxy && completerProxy->sourceModel() == model) {
218 row = completerProxy->mapToSource(completerIndex).row();
219 } else {
220 QString match = q->completer()->model()->data(completerIndex).toString();
221 row = q->findText(match, matchFlags());
222 }
223 }
224 q->setCurrentIndex(row);
226 }
227 }
228#endif
229}
230#endif // QT_CONFIG(completer)
231
233{
234 Q_Q(QComboBox);
235 if (arrowState == state)
236 return;
239 q->initStyleOption(&opt);
240 q->update(q->rect());
241}
242
244{
245 Q_Q(QComboBox);
246 if (lineEdit) {
249 }
251 modelChanged();
252 q->update();
253}
254
256{
258}
259
261{
262 Q_Q(QComboBox);
263 bool currentReset = false;
264
265 const int rowCount = q->count();
266 for (int pos = 0; pos < rowCount; ++pos) {
267 const QModelIndex idx(model->index(pos, modelColumn, root));
268 if (idx.flags() & Qt::ItemIsEnabled) {
269 setCurrentIndex(idx);
270 currentReset = true;
271 break;
272 }
273 }
274
275 if (!currentReset)
277}
278
279QRect QComboBoxPrivate::popupGeometry(const QPoint &globalPosition) const
280{
281 Q_Q(const QComboBox);
283 ? QWidgetPrivate::screenGeometry(q, globalPosition)
285}
286
288{
289
290 Q_Q(QComboBox);
291 QRect lastHoverRect = hoverRect;
292 QStyle::SubControl lastHoverControl = hoverControl;
293 bool doesHover = q->testAttribute(Qt::WA_Hover);
294 if (lastHoverControl != newHoverControl(pos) && doesHover) {
295 q->update(lastHoverRect);
296 q->update(hoverRect);
297 return true;
298 }
299 return !doesHover;
300}
301
303{
304 Q_Q(QComboBox);
306 q->initStyleOption(&opt);
307 opt.subControls = QStyle::SC_All;
308 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);
310 ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)
311 : QRect();
312 return hoverControl;
313}
314
315/*
316 Computes a size hint based on the maximum width
317 for the items in the combobox.
318*/
320{
321 Q_Q(const QComboBox);
322
323 int width = 0;
324 const int count = q->count();
325 const int iconWidth = q->iconSize().width() + 4;
326 const QFontMetrics &fontMetrics = q->fontMetrics();
327
328 for (int i = 0; i < count; ++i) {
329 const int textWidth = fontMetrics.horizontalAdvance(q->itemText(i));
330 if (q->itemIcon(i).isNull())
331 width = (qMax(width, textWidth));
332 else
333 width = (qMax(width, textWidth + iconWidth));
334 }
335
337 q->initStyleOption(&opt);
338 QSize tmp(width, 0);
339 tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);
340 return tmp.width();
341}
342
344{
345 Q_Q(const QComboBox);
346 if (!sh.isValid()) {
348 int count = q->count();
349 QSize iconSize = q->iconSize();
350 const QFontMetrics &fm = q->fontMetrics();
351
352 // text width
353 if (&sh == &sizeHint || minimumContentsLength == 0) {
354 switch (sizeAdjustPolicy) {
357 if (count == 0) {
358 sh.rwidth() = 7 * fm.horizontalAdvance(u'x');
359 } else {
360 for (int i = 0; i < count; ++i) {
361 if (!q->itemIcon(i).isNull()) {
362 hasIcon = true;
363 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));
364 } else {
365 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));
366 }
367 }
368 }
369 break;
371 ;
372 }
373 } else {
374 for (int i = 0; i < count && !hasIcon; ++i)
375 hasIcon = !q->itemIcon(i).isNull();
376 }
377 if (minimumContentsLength > 0)
378 sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.horizontalAdvance(u'X') + (hasIcon ? iconSize.width() + 4 : 0)));
381
382
383 // height
384 sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);
385 if (hasIcon) {
386 sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
387 }
388
389 // add style and strut values
391 q->initStyleOption(&opt);
392 sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);
393 }
394 return sh;
395}
396
398{
400}
401
403{
404 Q_Q(const QComboBox);
406 q->initStyleOption(&opt);
408 q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q));
409 if (lineEdit)
411 if (container)
413}
414
415
417{
418 if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
421 combo->updateGeometry();
422 combo->adjustSize();
423 combo->update();
424 }
425 }
426}
427
429{
431 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
432 QStyleOption myOpt;
433 myOpt.initFrom(this);
435 if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
436 setMask(mask.region);
437 }
438 } else {
439 clearMask();
440 }
442}
443
445{
447 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &cbOpt, combo)
448 && mask().isEmpty()) {
450 opt.initFrom(this);
451 QPainter p(this);
453 }
454
456}
457
459 : QFrame(parent, Qt::Popup), combo(parent)
460{
461 // we need the combobox and itemview
464
467
468 // setup container
470
471 // we need a vertical layout
473 layout->setSpacing(0);
475
476 // set item view
478
479 // add scroller arrows if style needs them
481 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
482 if (usePopup) {
485 top->hide();
486 bottom->hide();
487 } else {
488 setLineWidth(1);
489 }
490
491 if (top) {
492 layout->insertWidget(0, top);
493 connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
494 }
495 if (bottom) {
497 connect(bottom, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
498 }
499
500 // Some styles (Mac) have a margin at the top and bottom of the popup.
501 layout->insertSpacing(0, 0);
502 layout->addSpacing(0);
504}
505
507{
508#if QT_CONFIG(scrollbar)
509 if (view->verticalScrollBar())
510 view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
511#endif
512}
513
515{
516 if (top)
517 top->hide();
518 if (bottom)
519 bottom->hide();
520}
521
522/*
523 Hides or shows the scrollers when we emulate a popupmenu
524*/
526{
527#if QT_CONFIG(scrollbar)
528 if (!top || !bottom)
529 return;
530
531 if (isVisible() == false)
532 return;
533
535 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&
536 view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
537
538 bool needTop = view->verticalScrollBar()->value()
539 > (view->verticalScrollBar()->minimum() + topMargin());
540 bool needBottom = view->verticalScrollBar()->value()
541 < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin());
542 if (needTop)
543 top->show();
544 else
545 top->hide();
546 if (needBottom)
547 bottom->show();
548 else
549 bottom->hide();
550 } else {
551 top->hide();
552 bottom->hide();
553 }
554#endif // QT_CONFIG(scrollbar)
555}
556
557/*
558 Cleans up when the view is destroyed.
559*/
561{
562 view = nullptr;
564}
565
566/*
567 Returns the item view used for the combobox popup.
568*/
570{
571 return view;
572}
573
578{
580
581 // clean up old one
582 if (view) {
583 view->removeEventFilter(this);
584 view->viewport()->removeEventFilter(this);
585#if QT_CONFIG(scrollbar)
586 disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
587 this, SLOT(updateScrollers()));
588 disconnect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
589 this, SLOT(updateScrollers()));
590#endif
591 disconnect(view, SIGNAL(destroyed()),
592 this, SLOT(viewDestroyed()));
593
594 if (isAncestorOf(view))
595 delete view;
596 view = nullptr;
597 }
598
599 // setup the item view
600 view = itemView;
601 view->setParent(this);
602 view->setAttribute(Qt::WA_MacShowFocusRect, false);
603 qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);
604 view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
605 view->installEventFilter(this);
606 view->viewport()->installEventFilter(this);
607 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
609 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
610#if QT_CONFIG(scrollbar)
611 if (usePopup)
612 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
613#endif
615 usePopup) {
616 view->setMouseTracking(true);
617 }
619 view->setFrameStyle(QFrame::NoFrame);
620 view->setLineWidth(0);
622#if QT_CONFIG(scrollbar)
623 connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
624 this, SLOT(updateScrollers()));
625 connect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
626 this, SLOT(updateScrollers()));
627#endif
628 connect(view, SIGNAL(destroyed()),
629 this, SLOT(viewDestroyed()));
630}
631
636{
637 if (const QListView *lview = qobject_cast<const QListView*>(view))
638 return lview->spacing();
639#if QT_CONFIG(tableview)
640 if (const QTableView *tview = qobject_cast<const QTableView*>(view))
641 return tview->showGrid() ? 1 : 0;
642#endif
643 return 0;
644}
645
650{
651 QListView *lview = qobject_cast<QListView*>(view);
652 if (lview)
653 return 2 * lview->spacing(); // QListView::spacing is the padding around the item.
654#if QT_CONFIG(tableview)
655 QTableView *tview = qobject_cast<QTableView*>(view);
656 if (tview)
657 return tview->showGrid() ? 1 : 0;
658#endif
659 return 0;
660}
661
663{
664 if (!layout() || layout()->count() < 1)
665 return;
666
667 QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());
668 if (!boxLayout)
669 return;
670
672 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
673 const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
674
675 QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();
676 if (topSpacer)
677 topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
678
679 QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();
680 if (bottomSpacer && bottomSpacer != topSpacer)
681 bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
682
683 boxLayout->invalidate();
684}
685
687{
688 // add scroller arrows if style needs them
690 view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
691 combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));
694}
695
697{
698 if (e->type() == QEvent::StyleChange)
700
702}
703
704
706{
707 switch (e->type()) {
709 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);
710 switch (keyEvent->key()) {
711 case Qt::Key_Enter:
712 case Qt::Key_Return:
713#ifdef QT_KEYPAD_NAVIGATION
714 case Qt::Key_Select:
715#endif
716 if (view->currentIndex().isValid() && view->currentIndex().flags().testFlag(Qt::ItemIsEnabled)) {
717 combo->hidePopup();
719 }
720 return true;
721 case Qt::Key_Down:
722 if (!(keyEvent->modifiers() & Qt::AltModifier))
723 break;
725 case Qt::Key_F4:
726 combo->hidePopup();
727 return true;
728 default:
729#if QT_CONFIG(shortcut)
730 if (keyEvent->matches(QKeySequence::Cancel) && isVisible()) {
731 keyEvent->accept();
732 return true;
733 }
734#endif
735 break;
736 }
737 break;
738 }
740 if (isVisible()) {
741 QMouseEvent *m = static_cast<QMouseEvent *>(e);
742 QWidget *widget = static_cast<QWidget *>(o);
743 QPoint vector = widget->mapToGlobal(m->position().toPoint()) - initialClickPosition;
744 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
746 QModelIndex indexUnderMouse = view->indexAt(m->position().toPoint());
747 if (indexUnderMouse.isValid()
748 && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
749 view->setCurrentIndex(indexUnderMouse);
750 }
751 }
752 break;
754 maybeIgnoreMouseButtonRelease = false;
755 break;
757 bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
758
759 QMouseEvent *m = static_cast<QMouseEvent *>(e);
760 if (isVisible() && view->rect().contains(m->position().toPoint()) && view->currentIndex().isValid()
761 && !blockMouseReleaseTimer.isActive() && !ignoreEvent
762 && (view->currentIndex().flags().testFlag(Qt::ItemIsEnabled))
763 && (view->currentIndex().flags().testFlag(Qt::ItemIsSelectable))) {
764 combo->hidePopup();
766 return true;
767 }
768 break;
769 }
770 default:
771 break;
772 }
773 return QFrame::eventFilter(o, e);
774}
775
777{
778 combo->update();
779}
780
782{
784 combo->update();
785#if QT_CONFIG(graphicsview)
786 // QGraphicsScenePrivate::removePopup closes the combo box popup, it hides it non-explicitly.
787 // Hiding/showing the QComboBox after this will unexpectedly show the popup as well.
788 // Re-hiding the popup container makes sure it is explicitly hidden.
789 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget())
790 proxy->hide();
791#endif
792}
793
795{
796
798 opt.subControls = QStyle::SC_All;
799 opt.activeSubControls = QStyle::SC_ComboBoxArrow;
801 combo->mapFromGlobal(e->globalPosition().toPoint()),
802 combo);
803 if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
804 || (!combo->isEditable() && sc != QStyle::SC_None))
806 combo->hidePopup();
807}
808
810{
811 Q_UNUSED(e);
813 combo->hidePopup();
815 }
816}
817
819{
820 // ### This should use QComboBox's initStyleOption(), but it's protected
821 // perhaps, we could cheat by having the QCombo private instead?
823 opt.initFrom(combo);
824 opt.subControls = QStyle::SC_All;
825 opt.activeSubControls = QStyle::SC_None;
826 opt.editable = combo->isEditable();
827 return opt;
828}
829
919 : QWidget(*new QComboBoxPrivate(), parent, { })
920{
921 Q_D(QComboBox);
922 d->init();
923}
924
929 : QWidget(dd, parent, { })
930{
931 Q_D(QComboBox);
932 d->init();
933}
934
1009{
1010 Q_Q(QComboBox);
1011#ifdef Q_OS_MACOS
1012 // On OS X, only line edits and list views always get tab focus. It's only
1013 // when we enable full keyboard access that other controls can get tab focus.
1014 // When it's not editable, a combobox looks like a button, and it behaves as
1015 // such in this respect.
1016 if (!q->isEditable())
1017 q->setFocusPolicy(Qt::TabFocus);
1018 else
1019#endif
1020 q->setFocusPolicy(Qt::WheelFocus);
1021
1025 q->setModel(new QStandardItemModel(0, 1, q));
1026 if (!q->isEditable())
1027 q->setAttribute(Qt::WA_InputMethodEnabled, false);
1028 else
1029 q->setAttribute(Qt::WA_InputMethodEnabled);
1030}
1031
1033{
1034 if (container)
1035 return container;
1036
1037 Q_Q(QComboBox);
1041 updateDelegate(true);
1047 SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1049 QObject::connect(container, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));
1050 return container;
1051}
1052
1053
1055{
1057}
1058
1059void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
1060{
1061 Q_Q(QComboBox);
1062 if (inserting || topLeft.parent() != root)
1063 return;
1064
1066 sizeHint = QSize();
1068 q->updateGeometry();
1069 }
1070
1071 if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
1072 const QString text = q->itemText(currentIndex.row());
1073 if (lineEdit) {
1076 } else {
1078 }
1079 q->update();
1080#if QT_CONFIG(accessibility)
1081 QAccessibleValueChangeEvent event(q, text);
1082 QAccessible::updateAccessibility(&event);
1083#endif
1084 }
1085}
1086
1088{
1089 Q_Q(QComboBox);
1090 if (inserting || parent != root)
1091 return;
1092
1094 sizeHint = QSize();
1096 q->updateGeometry();
1097 }
1098
1099 // set current index if combo was previously empty and there is no placeholderText
1100 if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid() &&
1102 q->setCurrentIndex(0);
1103 // need to emit changed if model updated index "silently"
1104 } else if (currentIndex.row() != indexBeforeChange) {
1105 q->update();
1107 }
1108}
1109
1111{
1113}
1114
1115void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/)
1116{
1117 Q_Q(QComboBox);
1118 if (parent != root)
1119 return;
1120
1122 sizeHint = QSize();
1124 q->updateGeometry();
1125 }
1126
1127 // model has removed the last row
1128 if (model->rowCount(root) == 0) {
1130 return;
1131 }
1132
1133 // model has changed the currentIndex
1135 if (!currentIndex.isValid() && q->count()) {
1136 q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));
1137 return;
1138 }
1139 if (lineEdit) {
1140 lineEdit->setText(q->itemText(currentIndex.row()));
1142 }
1143 q->update();
1145 }
1146}
1147
1148
1150{
1151 if (!container)
1152 return;
1153 Q_Q(QComboBox);
1155 q->initStyleOption(&opt);
1156#if QT_CONFIG(menu)
1157 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1158 QMenu menu;
1162 } else
1163#endif
1164 {
1165 container->setPalette(q->palette());
1167 }
1168 if (lineEdit)
1169 lineEdit->setPalette(q->palette());
1170}
1171
1173{
1174#ifdef Q_OS_MACOS
1175 Q_Q(QComboBox);
1176
1177 // See comment in QComboBoxPrivate::init()
1178 if (q->isEditable())
1179 q->setFocusPolicy(Qt::WheelFocus);
1180 else
1181 q->setFocusPolicy(Qt::TabFocus);
1182#endif
1183}
1184
1193{
1194 if (!option)
1195 return;
1196
1197 Q_D(const QComboBox);
1198 option->initFrom(this);
1199 option->editable = isEditable();
1200 option->frame = d->frame;
1201 if (hasFocus() && !option->editable)
1203 option->subControls = QStyle::SC_All;
1204 if (d->arrowState == QStyle::State_Sunken) {
1205 option->activeSubControls = QStyle::SC_ComboBoxArrow;
1206 option->state |= d->arrowState;
1207 } else {
1208 option->activeSubControls = d->hoverControl;
1209 }
1210 option->currentText = currentText();
1211 if (d->currentIndex.isValid()) {
1212 option->currentIcon = d->itemIcon(d->currentIndex);
1213 QVariant alignment = d->model->data(d->currentIndex, Qt::TextAlignmentRole);
1214 if (alignment.isValid())
1215 option->textAlignment = static_cast<Qt::Alignment>(alignment.toUInt());
1216 }
1217 option->iconSize = iconSize();
1218 if (d->container && d->container->isVisible())
1219 option->state |= QStyle::State_On;
1220}
1221
1223{
1224 if (!lineEdit)
1225 return;
1226
1227 Q_Q(QComboBox);
1229 q->initStyleOption(&opt);
1230 QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,
1232 if (!q->itemIcon(q->currentIndex()).isNull()) {
1233 QRect comboRect(editRect);
1234 editRect.setWidth(editRect.width() - q->iconSize().width() - 4);
1235 editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,
1236 editRect.size(), comboRect);
1237 }
1238 lineEdit->setGeometry(editRect);
1239}
1240
1241Qt::MatchFlags QComboBoxPrivate::matchFlags() const
1242{
1243 // Base how duplicates are determined on the autocompletion case sensitivity
1244 Qt::MatchFlags flags = Qt::MatchFixedString;
1245#if QT_CONFIG(completer)
1246 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)
1247#endif
1249 return flags;
1250}
1251
1252
1254{
1255 Q_Q(QComboBox);
1256 if (!lineEdit)
1257 return;
1258 const auto leText = lineEdit->text();
1259 if (!leText.isEmpty() && itemText(currentIndex) != leText) {
1260#if QT_CONFIG(completer)
1261 const auto *leCompleter = lineEdit->completer();
1262 const auto *popup = leCompleter ? QCompleterPrivate::get(leCompleter)->popup : nullptr;
1263 if (popup && popup->isVisible()) {
1264 // QLineEdit::editingFinished() will be emitted before the code flow returns
1265 // to QCompleter::eventFilter(), where QCompleter::activated() may be emitted.
1266 // We know that the completer popup will still be visible at this point, and
1267 // that any selection should be valid.
1268 const QItemSelectionModel *selModel = popup->selectionModel();
1269 const QModelIndex curIndex = popup->currentIndex();
1270 const bool completerIsActive = selModel && selModel->selectedIndexes().contains(curIndex);
1271
1272 if (completerIsActive)
1273 return;
1274 }
1275#endif
1276 const int index = q_func()->findText(leText, matchFlags());
1277 if (index != -1) {
1278 q->setCurrentIndex(index);
1280 }
1281 }
1282
1283}
1284
1286{
1287 Q_Q(QComboBox);
1288
1289 // The insertion code below does not apply when the policy is QComboBox::NoInsert.
1290 // In case a completer is installed, item activation via the completer is handled
1291 // in _q_completerActivated(). Otherwise _q_editingFinished() updates the current
1292 // index as appropriate.
1294 return;
1295
1296 if (lineEdit && !lineEdit->text().isEmpty()) {
1297 if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
1298 return;
1299 lineEdit->deselect();
1300 lineEdit->end(false);
1302 // check for duplicates (if not enabled) and quit
1303 int index = -1;
1304 if (!duplicatesEnabled) {
1305 index = q->findText(text, matchFlags());
1306 if (index != -1) {
1307 q->setCurrentIndex(index);
1309 return;
1310 }
1311 }
1312 switch (insertPolicy) {
1314 index = 0;
1315 break;
1317 index = q->count();
1318 break;
1322 if (!q->count() || !currentIndex.isValid())
1323 index = 0;
1325 q->setItemText(q->currentIndex(), text);
1327 index = q->currentIndex() + 1;
1329 index = q->currentIndex();
1330 break;
1332 index = 0;
1333 for (int i = 0; i < q->count(); ++i, ++index) {
1334 if (text.toLower() < q->itemText(i).toLower())
1335 break;
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341 if (index >= 0) {
1342 q->insertItem(index, text);
1343 q->setCurrentIndex(index);
1345 }
1346 }
1347}
1348
1350{
1351 Q_Q(QComboBox);
1352 if (item != currentIndex) {
1354 } else if (lineEdit) {
1356 lineEdit->setText(q->itemText(currentIndex.row()));
1357 }
1359}
1360
1362{
1363 Q_Q(QComboBox);
1364 if (!index.isValid())
1365 return;
1367 emit q->activated(index.row());
1368 emit q->textActivated(text);
1369}
1370
1372{
1373 Q_Q(QComboBox);
1374 if (!index.isValid())
1375 return;
1377 emit q->highlighted(index.row());
1378 emit q->textHighlighted(text);
1379}
1380
1382{
1383 Q_Q(QComboBox);
1384 const QString text = itemText(index);
1385 emit q->currentIndexChanged(index.row());
1386 // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
1387 if (!lineEdit)
1389#if QT_CONFIG(accessibility)
1390 QAccessibleValueChangeEvent event(q, text);
1391 QAccessible::updateAccessibility(&event);
1392#endif
1393}
1394
1396{
1397 return index.isValid() ? model->data(index, itemRole()).toString() : QString();
1398}
1399
1401{
1402 return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
1403}
1404
1409{
1410 // ### check delegateparent and delete delegate if us?
1411 Q_D(QComboBox);
1412
1413 QT_TRY {
1414 disconnect(d->model, SIGNAL(destroyed()),
1415 this, SLOT(_q_modelDestroyed()));
1416 } QT_CATCH(...) {
1417 ; // objects can't throw in destructor
1418 }
1419}
1420
1431{
1432 Q_D(const QComboBox);
1433 return d->maxVisibleItems;
1434}
1435
1437{
1438 Q_D(QComboBox);
1439 if (Q_UNLIKELY(maxItems < 0)) {
1440 qWarning("QComboBox::setMaxVisibleItems: "
1441 "Invalid max visible items (%d) must be >= 0", maxItems);
1442 return;
1443 }
1444 d->maxVisibleItems = maxItems;
1445}
1446
1454{
1455 Q_D(const QComboBox);
1456 return d->model->rowCount(d->root);
1457}
1458
1472{
1473 Q_D(QComboBox);
1474 if (Q_UNLIKELY(max < 0)) {
1475 qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
1476 return;
1477 }
1478
1479 const int rowCount = count();
1480 if (rowCount > max)
1481 d->model->removeRows(max, rowCount - max, d->root);
1482
1483 d->maxCount = max;
1484}
1485
1487{
1488 Q_D(const QComboBox);
1489 return d->maxCount;
1490}
1491
1502{
1503 Q_D(const QComboBox);
1504 return d->duplicatesEnabled;
1505}
1506
1508{
1509 Q_D(QComboBox);
1510 d->duplicatesEnabled = enable;
1511}
1512
1527int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const
1528{
1529 Q_D(const QComboBox);
1530 QModelIndex start = d->model->index(0, d->modelColumn, d->root);
1531 const QModelIndexList result = d->model->match(start, role, data, 1, flags);
1532 if (result.isEmpty())
1533 return -1;
1534 return result.first().row();
1535}
1536
1549{
1550 Q_D(const QComboBox);
1551 return d->insertPolicy;
1552}
1553
1555{
1556 Q_D(QComboBox);
1557 d->insertPolicy = policy;
1558}
1559
1571{
1572 Q_D(const QComboBox);
1573 return d->sizeAdjustPolicy;
1574}
1575
1577{
1578 Q_D(QComboBox);
1579 if (policy == d->sizeAdjustPolicy)
1580 return;
1581
1582 d->sizeAdjustPolicy = policy;
1583 d->sizeHint = QSize();
1584 d->adjustComboBoxSize();
1586}
1587
1600{
1601 Q_D(const QComboBox);
1602 return d->minimumContentsLength;
1603}
1604
1606{
1607 Q_D(QComboBox);
1608 if (characters == d->minimumContentsLength || characters < 0)
1609 return;
1610
1611 d->minimumContentsLength = characters;
1612
1613 if (d->sizeAdjustPolicy == AdjustToContents
1614 || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
1615 d->sizeHint = QSize();
1616 d->adjustComboBoxSize();
1618 }
1619}
1620
1631{
1632 Q_D(const QComboBox);
1633 if (d->iconSize.isValid())
1634 return d->iconSize;
1635
1636 int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
1637 return QSize(iconWidth, iconWidth);
1638}
1639
1641{
1642 Q_D(QComboBox);
1643 if (size == d->iconSize)
1644 return;
1645
1646 view()->setIconSize(size);
1647 d->iconSize = size;
1648 d->sizeHint = QSize();
1650}
1651
1668void QComboBox::setPlaceholderText(const QString &placeholderText)
1669{
1670 Q_D(QComboBox);
1671 if (placeholderText == d->placeholderText)
1672 return;
1673
1674 d->placeholderText = placeholderText;
1675 if (currentIndex() == -1) {
1676 if (d->placeholderText.isEmpty())
1677 setCurrentIndex(0);
1678 else
1679 update();
1680 } else {
1682 }
1683}
1684
1686{
1687 Q_D(const QComboBox);
1688 return d->placeholderText;
1689}
1690
1704{
1705 Q_D(const QComboBox);
1706 return d->lineEdit != nullptr;
1707}
1708
1717{
1718 Q_Q(QComboBox);
1720 q->initStyleOption(&opt);
1721 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1722 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
1723 q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
1724 } else {
1725 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
1726 q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
1727 }
1728}
1729
1731{
1732 if (!index.isValid())
1733 return {};
1735 if (decoration.userType() == QMetaType::QPixmap)
1736 return QIcon(qvariant_cast<QPixmap>(decoration));
1737 else
1738 return qvariant_cast<QIcon>(decoration);
1739}
1740
1741void QComboBox::setEditable(bool editable)
1742{
1743 Q_D(QComboBox);
1744 if (isEditable() == editable)
1745 return;
1746
1749 if (editable) {
1750 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1751 d->viewContainer()->updateScrollers();
1752 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
1753 }
1754 QLineEdit *le = new QLineEdit(this);
1755 le->setPalette(palette());
1756 setLineEdit(le);
1757 } else {
1758 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1759 d->viewContainer()->updateScrollers();
1760 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1761 }
1763 d->lineEdit->hide();
1764 d->lineEdit->deleteLater();
1765 d->lineEdit = nullptr;
1766 }
1767
1768 d->updateDelegate();
1769 d->updateFocusPolicy();
1770
1771 d->viewContainer()->updateTopBottomMargin();
1773 adjustSize();
1774}
1775
1785{
1786 Q_D(QComboBox);
1787 if (Q_UNLIKELY(!edit)) {
1788 qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
1789 return;
1790 }
1791
1792 if (edit == d->lineEdit)
1793 return;
1794
1796 delete d->lineEdit;
1797
1798 d->lineEdit = edit;
1799#ifndef QT_NO_IM
1801#endif
1802 if (d->lineEdit->parent() != this)
1803 d->lineEdit->setParent(this);
1804 connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));
1805 connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished()));
1808 connect(d->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateMicroFocus()));
1809 connect(d->lineEdit, SIGNAL(selectionChanged()), this, SLOT(updateMicroFocus()));
1810 connect(d->lineEdit->d_func()->control, SIGNAL(updateMicroFocus()), this, SLOT(updateMicroFocus()));
1811 d->lineEdit->setFrame(false);
1812 d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
1813 d->updateFocusPolicy();
1814 d->lineEdit->setFocusProxy(this);
1815 d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
1816
1817#if QT_CONFIG(completer)
1818 // create a default completer
1819 if (!d->lineEdit->completer()) {
1820 QCompleter *completer = new QCompleter(d->model, d->lineEdit);
1823 completer->setCompletionColumn(d->modelColumn);
1824
1825#ifdef QT_KEYPAD_NAVIGATION
1826 // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
1827 // This means that when the user enters edit mode they are immediately presented with a
1828 // list of possible completions.
1829 if (QApplicationPrivate::keypadNavigationEnabled())
1831#endif
1832 // sets up connections
1834 }
1835#endif
1836
1838 d->updateLayoutDirection();
1839 d->updateLineEditGeometry();
1840 if (isVisible())
1841 d->lineEdit->show();
1842
1843 update();
1844}
1845
1853{
1854 Q_D(const QComboBox);
1855 return d->lineEdit;
1856}
1857
1858#ifndef QT_NO_VALIDATOR
1868{
1869 Q_D(QComboBox);
1870 if (d->lineEdit)
1871 d->lineEdit->setValidator(v);
1872}
1873
1881{
1882 Q_D(const QComboBox);
1883 return d->lineEdit ? d->lineEdit->validator() : nullptr;
1884}
1885#endif // QT_NO_VALIDATOR
1886
1887#if QT_CONFIG(completer)
1888
1903void QComboBox::setCompleter(QCompleter *c)
1904{
1905 Q_D(QComboBox);
1906 if (!d->lineEdit) {
1907 qWarning("Setting a QCompleter on non-editable QComboBox is not allowed.");
1908 return;
1909 }
1910 d->lineEdit->setCompleter(c);
1911 if (c) {
1912 connect(c, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));
1913 c->setWidget(this);
1914 }
1915}
1916
1925QCompleter *QComboBox::completer() const
1926{
1927 Q_D(const QComboBox);
1928 return d->lineEdit ? d->lineEdit->completer() : nullptr;
1929}
1930
1931#endif // QT_CONFIG(completer)
1932
1939{
1940 return view()->itemDelegate();
1941}
1942
1959{
1960 if (Q_UNLIKELY(!delegate)) {
1961 qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
1962 return;
1963 }
1964 view()->setItemDelegate(delegate);
1965}
1966
1972{
1973 Q_D(const QComboBox);
1975 QComboBox *that = const_cast<QComboBox*>(this);
1976 that->setModel(new QStandardItemModel(0, 1, that));
1977 }
1978 return d->model;
1979}
1980
1991{
1992 Q_D(QComboBox);
1993
1994 if (Q_UNLIKELY(!model)) {
1995 qWarning("QComboBox::setModel: cannot set a 0 model");
1996 return;
1997 }
1998
1999 if (model == d->model)
2000 return;
2001
2002#if QT_CONFIG(completer)
2003 if (d->lineEdit && d->lineEdit->completer())
2004 d->lineEdit->completer()->setModel(model);
2005#endif
2006 if (d->model) {
2007 disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
2008 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2009 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2010 this, SLOT(_q_updateIndexBeforeChange()));
2011 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2012 this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2013 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2014 this, SLOT(_q_updateIndexBeforeChange()));
2015 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2016 this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2017 disconnect(d->model, SIGNAL(destroyed()),
2018 this, SLOT(_q_modelDestroyed()));
2019 disconnect(d->model, SIGNAL(modelAboutToBeReset()),
2020 this, SLOT(_q_updateIndexBeforeChange()));
2021 disconnect(d->model, SIGNAL(modelReset()),
2022 this, SLOT(_q_modelReset()));
2023 if (d->model->QObject::parent() == this)
2024 delete d->model;
2025 }
2026
2027 d->model = model;
2028
2030 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2031 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2032 this, SLOT(_q_updateIndexBeforeChange()));
2033 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2034 this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2035 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2036 this, SLOT(_q_updateIndexBeforeChange()));
2037 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2038 this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2040 this, SLOT(_q_modelDestroyed()));
2041 connect(model, SIGNAL(modelAboutToBeReset()),
2042 this, SLOT(_q_updateIndexBeforeChange()));
2043 connect(model, SIGNAL(modelReset()),
2044 this, SLOT(_q_modelReset()));
2045
2046 if (d->container) {
2047 d->container->itemView()->setModel(model);
2048 connect(d->container->itemView()->selectionModel(),
2049 SIGNAL(currentChanged(QModelIndex,QModelIndex)),
2050 this, SLOT(_q_emitHighlighted(QModelIndex)), Qt::UniqueConnection);
2051 }
2052
2054
2055 d->trySetValidIndex();
2056 d->modelChanged();
2057}
2058
2066{
2067 Q_D(const QComboBox);
2068 return QModelIndex(d->root);
2069}
2070
2077{
2078 Q_D(QComboBox);
2079 if (d->root == index)
2080 return;
2081 d->root = QPersistentModelIndex(index);
2083 update();
2084}
2085
2096{
2097 Q_D(const QComboBox);
2098 return d->currentIndex.row();
2099}
2100
2102{
2103 Q_D(QComboBox);
2104 QModelIndex mi = index >= 0 ? d->model->index(index, d->modelColumn, d->root) : QModelIndex();
2105 d->setCurrentIndex(mi);
2106}
2107
2109{
2110 if (isEditable()) {
2112 } else {
2113 const int i = findText(text);
2114 if (i > -1)
2116 }
2117}
2118
2120{
2121 Q_Q(QComboBox);
2122
2123 QModelIndex normalized = mi.sibling(mi.row(), modelColumn); // no-op if mi.column() == modelColumn
2124 if (!normalized.isValid())
2125 normalized = mi; // Fallback to passed index.
2126
2127 bool indexChanged = (normalized != currentIndex);
2128 if (indexChanged)
2130 if (lineEdit) {
2131 const QString newText = itemText(normalized);
2132 if (lineEdit->text() != newText) {
2133 lineEdit->setText(newText); // may cause lineEdit -> nullptr (QTBUG-54191)
2134#if QT_CONFIG(completer)
2135 if (lineEdit && lineEdit->completer())
2136 lineEdit->completer()->setCompletionPrefix(newText);
2137#endif
2138 }
2140 }
2141 // If the model was reset to an empty one, currentIndex will be invalidated
2142 // (because it's a QPersistentModelIndex), but the index change will never
2143 // be advertised. So an explicit check for this condition is needed.
2144 // The variable used for that check has to be reset when a previously valid
2145 // index becomes invalid.
2146 const bool modelResetToEmpty = !normalized.isValid() && indexBeforeChange != -1;
2147 if (modelResetToEmpty)
2148 indexBeforeChange = -1;
2149
2150 if (indexChanged || modelResetToEmpty) {
2151 q->update();
2153 }
2154}
2155
2171{
2172 Q_D(const QComboBox);
2173 if (d->lineEdit)
2174 return d->lineEdit->text();
2175 if (d->currentIndex.isValid())
2176 return d->itemText(d->currentIndex);
2177 return {};
2178}
2179
2189{
2190 Q_D(const QComboBox);
2191 return d->currentIndex.data(role);
2192}
2193
2198{
2199 Q_D(const QComboBox);
2200 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2201 return d->itemText(mi);
2202}
2203
2208{
2209 Q_D(const QComboBox);
2210 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2211 return d->itemIcon(mi);
2212}
2213
2219{
2220 Q_D(const QComboBox);
2221 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2222 return d->model->data(mi, role);
2223}
2224
2251void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)
2252{
2253 Q_D(QComboBox);
2254 int itemCount = count();
2255 index = qBound(0, index, itemCount);
2256 if (index >= d->maxCount)
2257 return;
2258
2259 // For the common case where we are using the built in QStandardItemModel
2260 // construct a QStandardItem, reducing the number of expensive signals from the model
2261 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2264 if (userData.isValid()) item->setData(userData, Qt::UserRole);
2265 m->insertRow(index, item);
2266 ++itemCount;
2267 } else {
2268 d->inserting = true;
2269 if (d->model->insertRows(index, 1, d->root)) {
2270 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2271 if (icon.isNull() && !userData.isValid()) {
2272 d->model->setData(item, text, Qt::EditRole);
2273 } else {
2275 if (!text.isNull()) values.insert(Qt::EditRole, text);
2276 if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
2277 if (userData.isValid()) values.insert(Qt::UserRole, userData);
2278 if (!values.isEmpty()) d->model->setItemData(item, values);
2279 }
2280 d->inserting = false;
2281 d->_q_rowsInserted(d->root, index, index);
2282 ++itemCount;
2283 } else {
2284 d->inserting = false;
2285 }
2286 }
2287
2288 if (itemCount > d->maxCount)
2289 d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
2290}
2291
2303{
2304 Q_D(QComboBox);
2305 if (list.isEmpty())
2306 return;
2307 index = qBound(0, index, count());
2308 int insertCount = qMin(d->maxCount - index, list.size());
2309 if (insertCount <= 0)
2310 return;
2311 // For the common case where we are using the built in QStandardItemModel
2312 // construct a QStandardItem, reducing the number of expensive signals from the model
2313 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2315 items.reserve(insertCount);
2316 QStandardItem *hiddenRoot = m->invisibleRootItem();
2317 for (int i = 0; i < insertCount; ++i)
2319 hiddenRoot->insertRows(index, items);
2320 } else {
2321 d->inserting = true;
2322 if (d->model->insertRows(index, insertCount, d->root)) {
2324 for (int i = 0; i < insertCount; ++i) {
2325 item = d->model->index(i+index, d->modelColumn, d->root);
2326 d->model->setData(item, list.at(i), Qt::EditRole);
2327 }
2328 d->inserting = false;
2329 d->_q_rowsInserted(d->root, index, index + insertCount - 1);
2330 } else {
2331 d->inserting = false;
2332 }
2333 }
2334
2335 int mc = count();
2336 if (mc > d->maxCount)
2337 d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);
2338}
2339
2352{
2353 Q_D(QComboBox);
2354 int itemCount = count();
2355 index = qBound(0, index, itemCount);
2356 if (index >= d->maxCount)
2357 return;
2359 QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));
2360}
2361
2369{
2370 Q_D(QComboBox);
2371 if (index < 0 || index >= count())
2372 return;
2373 d->model->removeRows(index, 1, d->root);
2374}
2375
2380{
2381 Q_D(const QComboBox);
2382 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2383 if (item.isValid()) {
2384 d->model->setData(item, text, Qt::EditRole);
2385 }
2386}
2387
2392{
2393 Q_D(const QComboBox);
2394 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2395 if (item.isValid()) {
2396 d->model->setData(item, icon, Qt::DecorationRole);
2397 }
2398}
2399
2404void QComboBox::setItemData(int index, const QVariant &value, int role)
2405{
2406 Q_D(const QComboBox);
2407 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2408 if (item.isValid()) {
2409 d->model->setData(item, value, role);
2410 }
2411}
2412
2417{
2418 Q_D(const QComboBox);
2419 return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();
2420}
2421
2432{
2433 Q_D(QComboBox);
2434 if (Q_UNLIKELY(!itemView)) {
2435 qWarning("QComboBox::setView: cannot set a 0 view");
2436 return;
2437 }
2438
2439 if (itemView->model() != d->model)
2440 itemView->setModel(d->model);
2441 d->viewContainer()->setItemView(itemView);
2442}
2443
2448{
2449 Q_D(const QComboBox);
2450 return d->recomputeSizeHint(d->minimumSizeHint);
2451}
2452
2461{
2462 Q_D(const QComboBox);
2463 return d->recomputeSizeHint(d->sizeHint);
2464}
2465
2466#ifdef Q_OS_MAC
2467void QComboBoxPrivate::cleanupNativePopup()
2468{
2469 if (!m_platformMenu)
2470 return;
2471
2472 int count = int(m_platformMenu->tag());
2473 for (int i = 0; i < count; ++i)
2474 m_platformMenu->menuItemAt(i)->deleteLater();
2475
2476 delete m_platformMenu;
2477 m_platformMenu = 0;
2478}
2479
2486bool QComboBoxPrivate::showNativePopup()
2487{
2488 Q_Q(QComboBox);
2489
2490 cleanupNativePopup();
2491
2493 m_platformMenu = theme->createPlatformMenu();
2494 if (!m_platformMenu)
2495 return false;
2496
2497 int itemsCount = q->count();
2498 m_platformMenu->setTag(quintptr(itemsCount));
2499
2500 QPlatformMenuItem *currentItem = nullptr;
2501 int currentIndex = q->currentIndex();
2502
2503 for (int i = 0; i < itemsCount; ++i) {
2505 QModelIndex rowIndex = model->index(i, modelColumn, root);
2506 QVariant textVariant = model->data(rowIndex, Qt::EditRole);
2507 item->setText(textVariant.toString());
2508 QVariant iconVariant = model->data(rowIndex, Qt::DecorationRole);
2509 const Qt::ItemFlags itemFlags = model->flags(rowIndex);
2510 if (iconVariant.canConvert<QIcon>())
2511 item->setIcon(iconVariant.value<QIcon>());
2512 item->setCheckable(true);
2513 item->setChecked(i == currentIndex);
2514 item->setEnabled(itemFlags & Qt::ItemIsEnabled);
2515 if (!currentItem || i == currentIndex)
2516 currentItem = item;
2517
2518 IndexSetter setter = { i, q };
2520
2521 m_platformMenu->insertMenuItem(item, 0);
2522 m_platformMenu->syncMenuItem(item);
2523 }
2524
2525 QWindow *tlw = q->window()->windowHandle();
2526 m_platformMenu->setFont(q->font());
2527 m_platformMenu->setMinimumWidth(q->rect().width());
2528 QPoint offset = QPoint(0, 7);
2529 if (q->testAttribute(Qt::WA_MacSmallSize))
2530 offset = QPoint(-1, 7);
2531 else if (q->testAttribute(Qt::WA_MacMiniSize))
2532 offset = QPoint(-2, 6);
2533
2534 const QRect targetRect = QRect(tlw->mapFromGlobal(q->mapToGlobal(offset)), QSize());
2535 m_platformMenu->showPopup(tlw, QHighDpi::toNativePixels(targetRect, tlw), currentItem);
2536
2537#ifdef Q_OS_MACOS
2538 // The Cocoa popup will swallow any mouse release event.
2539 // We need to fake one here to un-press the button.
2540 QMouseEvent mouseReleased(QEvent::MouseButtonRelease, q->pos(), q->mapToGlobal(QPoint(0, 0)),
2541 Qt::LeftButton, Qt::MouseButtons(Qt::LeftButton), {});
2542 QCoreApplication::sendEvent(q, &mouseReleased);
2543#endif
2544
2545 return true;
2546}
2547
2548#endif // Q_OS_MAC
2549
2560{
2561 Q_D(QComboBox);
2562 if (count() <= 0)
2563 return;
2564
2565 QStyle * const style = this->style();
2568 const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
2569
2570#ifdef Q_OS_MAC
2571 if (usePopup
2572 && (!d->container
2573 || (view()->metaObject()->className() == QByteArray("QComboBoxListView")
2574 && view()->itemDelegate()->metaObject()->className() == QByteArray("QComboMenuDelegate")))
2576 && d->showNativePopup())
2577 return;
2578#endif // Q_OS_MAC
2579
2580 // set current item and select it
2581 QItemSelectionModel::SelectionFlags selectionMode = QItemSelectionModel::ClearAndSelect;
2582 if (view()->selectionBehavior() == QAbstractItemView::SelectRows)
2583 selectionMode.setFlag(QItemSelectionModel::Rows);
2584 view()->selectionModel()->setCurrentIndex(d->currentIndex, selectionMode);
2585 QComboBoxPrivateContainer* container = d->viewContainer();
2588 QRect screen = d->popupGeometry(mapToGlobal(listRect.topLeft()));
2589
2590 QPoint below = mapToGlobal(listRect.bottomLeft());
2591 int belowHeight = screen.bottom() - below.y();
2592 QPoint above = mapToGlobal(listRect.topLeft());
2593 int aboveHeight = above.y() - screen.y();
2594 bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);
2595
2596 {
2597 int listHeight = 0;
2598 int count = 0;
2599 QStack<QModelIndex> toCheck;
2600 toCheck.push(view()->rootIndex());
2601#if QT_CONFIG(treeview)
2602 QTreeView *treeView = qobject_cast<QTreeView*>(view());
2603 if (treeView && treeView->header() && !treeView->header()->isHidden())
2604 listHeight += treeView->header()->height();
2605#endif
2606 while (!toCheck.isEmpty()) {
2607 QModelIndex parent = toCheck.pop();
2608 for (int i = 0, end = d->model->rowCount(parent); i < end; ++i) {
2609 QModelIndex idx = d->model->index(i, d->modelColumn, parent);
2610 if (!idx.isValid())
2611 continue;
2612 listHeight += view()->visualRect(idx).height();
2613#if QT_CONFIG(treeview)
2614 if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
2615 toCheck.push(idx);
2616#endif
2617 ++count;
2618 if (!usePopup && count >= d->maxVisibleItems) {
2619 toCheck.clear();
2620 break;
2621 }
2622 }
2623 }
2624 if (count > 1)
2625 listHeight += (count - 1) * container->spacing();
2626 listRect.setHeight(listHeight);
2627 }
2628
2629 {
2630 // add the spacing for the grid on the top and the bottom;
2631 int heightMargin = container->topMargin() + container->bottomMargin();
2632
2633 // add the frame of the container
2634 const QMargins cm = container->contentsMargins();
2635 heightMargin += cm.top() + cm.bottom();
2636
2637 //add the frame of the view
2638 const QMargins vm = view()->contentsMargins();
2639 heightMargin += vm.top() + vm.bottom();
2640 heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
2641 heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
2642
2643 listRect.setHeight(listRect.height() + heightMargin);
2644 }
2645
2646 // Add space for margin at top and bottom if the style wants it.
2647 if (usePopup)
2648 listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
2649
2650 // Make sure the popup is wide enough to display its contents.
2651 if (usePopup) {
2652 const int diff = d->computeWidthHint() - width();
2653 if (diff > 0)
2654 listRect.setWidth(listRect.width() + diff);
2655 }
2656
2657 //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
2658 container->layout()->activate();
2659 //takes account of the minimum/maximum size of the container
2660 listRect.setSize( listRect.size().expandedTo(container->minimumSize())
2661 .boundedTo(container->maximumSize()));
2662
2663 // make sure the widget fits on screen
2664 if (boundToScreen) {
2665 if (listRect.width() > screen.width() )
2666 listRect.setWidth(screen.width());
2667 if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
2668 below.setX(screen.x() + screen.width() - listRect.width());
2669 above.setX(screen.x() + screen.width() - listRect.width());
2670 }
2671 if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
2672 below.setX(screen.x());
2673 above.setX(screen.x());
2674 }
2675 }
2676
2677 if (usePopup) {
2678 // Position horizontally.
2679 listRect.moveLeft(above.x());
2680
2681 // Position vertically so the currently selected item lines up
2682 // with the combo box. In order to do that, make sure that the item
2683 // view is scrolled to the top first, otherwise calls to view()->visualRect()
2684 // will return the geometry the selected item had the last time the popup
2685 // was visible (and perhaps scrolled). And this will not match the geometry
2686 // it will actually have when we resize the container to fit all the items
2687 // further down in this function.
2688 view()->scrollToTop();
2689 const QRect currentItemRect = view()->visualRect(view()->currentIndex());
2690 const int offset = listRect.top() - currentItemRect.top();
2691 listRect.moveTop(above.y() + offset - listRect.top());
2692
2693 // Clamp the listRect height and vertical position so we don't expand outside the
2694 // available screen geometry.This may override the vertical position, but it is more
2695 // important to show as much as possible of the popup.
2696 const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
2697 listRect.setHeight(height);
2698
2699 if (boundToScreen) {
2700 if (listRect.top() < screen.top())
2701 listRect.moveTop(screen.top());
2702 if (listRect.bottom() > screen.bottom())
2703 listRect.moveBottom(screen.bottom());
2704 }
2705 } else if (!boundToScreen || listRect.height() <= belowHeight) {
2706 listRect.moveTopLeft(below);
2707 } else if (listRect.height() <= aboveHeight) {
2708 listRect.moveBottomLeft(above);
2709 } else if (belowHeight >= aboveHeight) {
2710 listRect.setHeight(belowHeight);
2711 listRect.moveTopLeft(below);
2712 } else {
2713 listRect.setHeight(aboveHeight);
2714 listRect.moveBottomLeft(above);
2715 }
2716
2717 if (qApp) {
2719 }
2720
2721 const QScrollBar *sb = view()->horizontalScrollBar();
2722 const auto needHorizontalScrollBar = [this, sb]{
2723 const Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();
2725 && sb->minimum() < sb->maximum();
2726 };
2727 const bool neededHorizontalScrollBar = needHorizontalScrollBar();
2728 if (neededHorizontalScrollBar)
2729 listRect.adjust(0, 0, 0, sb->height());
2730
2731 // Hide the scrollers here, so that the listrect gets the full height of the container
2732 // If the scrollers are truly needed, the later call to container->updateScrollers()
2733 // will make them visible again.
2734 container->hideScrollers();
2735 container->setGeometry(listRect);
2736
2737#ifndef Q_OS_MAC
2738 const bool updatesEnabled = container->updatesEnabled();
2739#endif
2740
2741#if QT_CONFIG(effects)
2742 bool scrollDown = (listRect.topLeft() == below);
2745 qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
2746#endif
2747
2748// Don't disable updates on OS X. Windows are displayed immediately on this platform,
2749// which means that the window will be visible before the call to container->show() returns.
2750// If updates are disabled at this point we'll miss our chance at painting the popup
2751// menu before it's shown, causing flicker since the window then displays the standard gray
2752// background.
2753#ifndef Q_OS_MAC
2754 container->setUpdatesEnabled(false);
2755#endif
2756
2757 bool startTimer = !container->isVisible();
2758 container->raise();
2759 container->create();
2761 QScreen *currentScreen = d->associatedScreen();
2762 if (currentScreen && !currentScreen->virtualSiblings().contains(containerWindow->screen())) {
2763 containerWindow->setScreen(currentScreen);
2764
2765 // This seems to workaround an issue in xcb+multi GPU+multiscreen
2766 // environment where the window might not always show up when screen
2767 // is changed.
2768 container->hide();
2769 }
2770 }
2771 container->show();
2772 if (!neededHorizontalScrollBar && needHorizontalScrollBar()) {
2773 listRect.adjust(0, 0, 0, sb->height());
2774 container->setGeometry(listRect);
2775 }
2776
2777 container->updateScrollers();
2778 view()->setFocus();
2779
2784
2785#ifndef Q_OS_MAC
2787#endif
2788
2789 container->update();
2790 if (startTimer) {
2791 container->popupTimer.start();
2792 container->maybeIgnoreMouseButtonRelease = true;
2793 }
2794}
2795
2807{
2808 Q_D(QComboBox);
2809 if (d->hidingPopup)
2810 return;
2811 d->hidingPopup = true;
2812 // can't use QBoolBlocker on a bitfield
2813 auto resetHidingPopup = qScopeGuard([d]{
2814 d->hidingPopup = false;
2815 });
2816
2817 if (!d->container || !d->container->isVisible())
2818 return;
2819
2820#if QT_CONFIG(effects)
2821 QItemSelectionModel *selectionModel = d->container->itemView()
2822 ? d->container->itemView()->selectionModel() : nullptr;
2823 // Flash selected/triggered item (if any) before hiding the popup.
2824 if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem) &&
2825 selectionModel && selectionModel->hasSelection()) {
2826 const QItemSelection selection = selectionModel->selection();
2827
2828 QTimer::singleShot(0, d->container, [d, selection, selectionModel]{
2829 QSignalBlocker modelBlocker(d->model);
2830 QSignalBlocker viewBlocker(d->container->itemView());
2831 QSignalBlocker containerBlocker(d->container);
2832
2833 // Deselect item and wait 60 ms.
2834 selectionModel->select(selection, QItemSelectionModel::Toggle);
2835 QTimer::singleShot(60, d->container, [d, selection, selectionModel]{
2836 QSignalBlocker modelBlocker(d->model);
2837 QSignalBlocker viewBlocker(d->container->itemView());
2838 QSignalBlocker containerBlocker(d->container);
2839 selectionModel->select(selection, QItemSelectionModel::Toggle);
2840 QTimer::singleShot(20, d->container, [d] {
2841 d->doHidePopup();
2842 });
2843 });
2844 });
2845 } else
2846#endif // QT_CONFIG(effects)
2847 {
2848 d->doHidePopup();
2849 }
2850}
2851
2853{
2854 if (container && container->isVisible())
2855 container->hide();
2856
2858}
2859
2861{
2862 if (text == currentText)
2863 return;
2864
2865 currentText = text;
2866 emit q_func()->currentTextChanged(text);
2867}
2868
2876{
2877 Q_D(QComboBox);
2878 d->model->removeRows(0, d->model->rowCount(d->root), d->root);
2879#if QT_CONFIG(accessibility)
2880 QAccessibleValueChangeEvent event(this, QString());
2881 QAccessible::updateAccessibility(&event);
2882#endif
2883}
2884
2889{
2890 Q_D(QComboBox);
2891 if (d->lineEdit)
2892 d->lineEdit->clear();
2893#if QT_CONFIG(accessibility)
2894 QAccessibleValueChangeEvent event(this, QString());
2895 QAccessible::updateAccessibility(&event);
2896#endif
2897}
2898
2903{
2904 Q_D(QComboBox);
2905 if (d->lineEdit)
2906 d->lineEdit->setText(text);
2907#if QT_CONFIG(accessibility)
2908 QAccessibleValueChangeEvent event(this, text);
2909 QAccessible::updateAccessibility(&event);
2910#endif
2911}
2912
2917{
2918 Q_D(QComboBox);
2919 update();
2920 if (d->lineEdit) {
2921 d->lineEdit->event(e);
2922#if QT_CONFIG(completer)
2923 if (d->lineEdit->completer())
2924 d->lineEdit->completer()->setWidget(this);
2925#endif
2926 }
2927}
2928
2933{
2934 Q_D(QComboBox);
2935 update();
2936 if (d->lineEdit)
2937 d->lineEdit->event(e);
2938}
2939
2942{
2943 Q_D(QComboBox);
2944 switch (e->type()) {
2946 if (d->container)
2947 d->container->updateStyleSettings();
2948 d->updateDelegate();
2949#ifdef Q_OS_MAC
2951#endif
2952 d->sizeHint = QSize(); // invalidate size hint
2953 d->minimumSizeHint = QSize();
2954 d->updateLayoutDirection();
2955 if (d->lineEdit)
2956 d->updateLineEditGeometry();
2957 d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
2958
2959 if (e->type() == QEvent::MacSizeChange) {
2966 QFont f = font();
2967 f.setPointSizeF(platformFont->pointSizeF());
2968 setFont(f);
2969 }
2970 }
2971 // ### need to update scrollers etc. as well here
2972 break;
2974 if (!isEnabled())
2975 hidePopup();
2976 break;
2977 case QEvent::PaletteChange: {
2978 d->updateViewContainerPaletteAndOpacity();
2979 break;
2980 }
2981 case QEvent::FontChange: {
2982 d->sizeHint = QSize(); // invalidate size hint
2983 d->viewContainer()->setFont(font());
2984 d->viewContainer()->itemView()->doItemsLayout();
2985 if (d->lineEdit)
2986 d->updateLineEditGeometry();
2987 break;
2988 }
2989 default:
2990 break;
2991 }
2993}
2994
2999{
3000 Q_D(QComboBox);
3001 d->updateLineEditGeometry();
3002}
3003
3008{
3009 QStylePainter painter(this);
3011
3012 // draw the combobox frame, focusrect and selected etc.
3015 painter.drawComplexControl(QStyle::CC_ComboBox, opt);
3016
3017 if (currentIndex() < 0 && !placeholderText().isEmpty()) {
3019 opt.currentText = placeholderText();
3020 }
3021
3022 // draw the icon and text
3023 painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
3024}
3025
3030{
3031 Q_D(QComboBox);
3032 if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
3033 d->sizeHint = QSize();
3035 }
3036 d->shownOnce = true;
3038}
3039
3044{
3045 hidePopup();
3046}
3047
3052{
3053 Q_D(QComboBox);
3054 switch(event->type()) {
3057 d->updateLayoutDirection();
3058 d->updateLineEditGeometry();
3059 break;
3060 case QEvent::HoverEnter:
3061 case QEvent::HoverLeave:
3062 case QEvent::HoverMove:
3063 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
3064 d->updateHoverControl(he->position().toPoint());
3065 break;
3067 if (d->lineEdit)
3068 return d->lineEdit->event(event);
3069 break;
3070#ifdef QT_KEYPAD_NAVIGATION
3071 case QEvent::EnterEditFocus:
3072 if (d->lineEdit)
3073 d->lineEdit->event(event); //so cursor starts
3074 break;
3075 case QEvent::LeaveEditFocus:
3076 if (d->lineEdit)
3077 d->lineEdit->event(event); //so cursor stops
3078 break;
3079#endif
3080 default:
3081 break;
3082 }
3083 return QWidget::event(event);
3084}
3085
3090{
3091 Q_D(QComboBox);
3092 if (!QGuiApplication::styleHints()->setFocusOnTouchRelease())
3093 d->showPopupFromMouseEvent(e);
3094}
3095
3097{
3098 Q_Q(QComboBox);
3100 q->initStyleOption(&opt);
3101 QStyle::SubControl sc = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->position().toPoint(), q);
3102
3103 if (e->button() == Qt::LeftButton
3104 && !(sc == QStyle::SC_None && e->type() == QEvent::MouseButtonRelease)
3105 && (sc == QStyle::SC_ComboBoxArrow || !q->isEditable())
3106 && !viewContainer()->isVisible()) {
3107 if (sc == QStyle::SC_ComboBoxArrow)
3109#ifdef QT_KEYPAD_NAVIGATION
3110 //if the container already exists, then d->viewContainer() is safe to call
3111 if (container) {
3112#else
3113 if (true) {
3114#endif
3115 // We've restricted the next couple of lines, because by not calling
3116 // viewContainer(), we avoid creating the QComboBoxPrivateContainer.
3117 viewContainer()->initialClickPosition = q->mapToGlobal(e->position().toPoint());
3118 }
3119 q->showPopup();
3120 // The code below ensures that regular mousepress and pick item still works
3121 // If it was not called the viewContainer would ignore event since it didn't have
3122 // a mousePressEvent first.
3123 if (viewContainer()) {
3125 viewContainer()->maybeIgnoreMouseButtonRelease = false;
3126 }
3127 } else {
3128#ifdef QT_KEYPAD_NAVIGATION
3129 if (QApplicationPrivate::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) {
3130 lineEdit->event(e); //so lineedit can move cursor, etc
3131 return;
3132 }
3133#endif
3134 e->ignore();
3135 }
3136}
3137
3142{
3143 Q_D(QComboBox);
3144 d->updateArrow(QStyle::State_None);
3145 if (QGuiApplication::styleHints()->setFocusOnTouchRelease() && hasFocus())
3146 d->showPopupFromMouseEvent(e);
3147}
3148
3153{
3154 Q_D(QComboBox);
3155
3156#if QT_CONFIG(completer)
3157 if (const auto *cmpltr = completer()) {
3158 const auto *popup = QCompleterPrivate::get(cmpltr)->popup;
3159 if (popup && popup->isVisible()) {
3160 // provide same autocompletion support as line edit
3161 d->lineEdit->event(e);
3162 return;
3163 }
3164 }
3165#endif
3166
3167 enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};
3168
3169 Move move = NoMove;
3170 int newIndex = currentIndex();
3171
3172 bool pressLikeButton = !d->lineEdit;
3173#ifdef QT_KEYPAD_NAVIGATION
3174 pressLikeButton |= QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus();
3175#endif
3176 auto key = e->key();
3177 if (pressLikeButton) {
3178 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()
3181 if (buttonPressKeys.contains(key)) {
3182 showPopup();
3183 return;
3184 }
3185 }
3186
3187 switch (key) {
3188 case Qt::Key_Up:
3189 if (e->modifiers() & Qt::ControlModifier)
3190 break; // pass to line edit for auto completion
3191 Q_FALLTHROUGH();
3192 case Qt::Key_PageUp:
3193#ifdef QT_KEYPAD_NAVIGATION
3194 if (QApplicationPrivate::keypadNavigationEnabled())
3195 e->ignore();
3196 else
3197#endif
3198 move = MoveUp;
3199 break;
3200 case Qt::Key_Down:
3201 if (e->modifiers() & Qt::AltModifier) {
3202 showPopup();
3203 return;
3204 } else if (e->modifiers() & Qt::ControlModifier)
3205 break; // pass to line edit for auto completion
3206 Q_FALLTHROUGH();
3207 case Qt::Key_PageDown:
3208#ifdef QT_KEYPAD_NAVIGATION
3209 if (QApplicationPrivate::keypadNavigationEnabled())
3210 e->ignore();
3211 else
3212#endif
3213 move = MoveDown;
3214 break;
3215 case Qt::Key_Home:
3216 if (!d->lineEdit)
3217 move = MoveFirst;
3218 break;
3219 case Qt::Key_End:
3220 if (!d->lineEdit)
3221 move = MoveLast;
3222 break;
3223 case Qt::Key_F4:
3224 if (!e->modifiers()) {
3225 showPopup();
3226 return;
3227 }
3228 break;
3229 case Qt::Key_Enter:
3230 case Qt::Key_Return:
3231 case Qt::Key_Escape:
3232 if (!d->lineEdit)
3233 e->ignore();
3234 break;
3235#ifdef QT_KEYPAD_NAVIGATION
3236 case Qt::Key_Left:
3237 case Qt::Key_Right:
3238 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
3239 e->ignore();
3240 break;
3241 case Qt::Key_Back:
3242 if (QApplicationPrivate::keypadNavigationEnabled()) {
3243 if (!hasEditFocus() || !d->lineEdit)
3244 e->ignore();
3245 } else {
3246 e->ignore(); // let the surrounding dialog have it
3247 }
3248 break;
3249#endif
3250 default:
3251#if QT_CONFIG(shortcut)
3252 if (d->container && d->container->isVisible() && e->matches(QKeySequence::Cancel)) {
3253 hidePopup();
3254 e->accept();
3255 }
3256#endif
3257
3258 if (!d->lineEdit) {
3259 if (!e->text().isEmpty())
3260 d->keyboardSearchString(e->text());
3261 else
3262 e->ignore();
3263 }
3264 }
3265
3266 const int rowCount = count();
3267
3268 if (move != NoMove) {
3269 e->accept();
3270 switch (move) {
3271 case MoveFirst:
3272 newIndex = -1;
3273 Q_FALLTHROUGH();
3274 case MoveDown:
3275 newIndex++;
3276 while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
3277 newIndex++;
3278 break;
3279 case MoveLast:
3280 newIndex = rowCount;
3281 Q_FALLTHROUGH();
3282 case MoveUp:
3283 newIndex--;
3284 while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3285 newIndex--;
3286 break;
3287 default:
3288 e->ignore();
3289 break;
3290 }
3291
3292 if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
3293 setCurrentIndex(newIndex);
3294 d->emitActivated(d->currentIndex);
3295 }
3296 } else if (d->lineEdit) {
3297 d->lineEdit->event(e);
3298 }
3299}
3300
3301
3306{
3307 Q_D(QComboBox);
3308 if (d->lineEdit)
3309 d->lineEdit->event(e);
3310 else
3312}
3313
3317#if QT_CONFIG(wheelevent)
3318void QComboBox::wheelEvent(QWheelEvent *e)
3319{
3320 Q_D(QComboBox);
3322 initStyleOption(&opt);
3323 if (style()->styleHint(QStyle::SH_ComboBox_AllowWheelScrolling, &opt, this) &&
3324 !d->viewContainer()->isVisible()) {
3325 const int rowCount = count();
3326 int newIndex = currentIndex();
3327 int delta = e->angleDelta().y();
3328
3329 if (delta > 0) {
3330 newIndex--;
3331 while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3332 newIndex--;
3333 } else if (delta < 0) {
3334 newIndex++;
3335 while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
3336 newIndex++;
3337 }
3338
3339 if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
3340 setCurrentIndex(newIndex);
3341 d->emitActivated(d->currentIndex);
3342 }
3343 e->accept();
3344 }
3345}
3346#endif
3347
3348#ifndef QT_NO_CONTEXTMENU
3353{
3354 Q_D(QComboBox);
3355 if (d->lineEdit) {
3356 Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();
3357 d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
3358 d->lineEdit->event(e);
3359 d->lineEdit->setContextMenuPolicy(p);
3360 }
3361}
3362#endif // QT_NO_CONTEXTMENU
3363
3365{
3366 // use keyboardSearch from the listView so we do not duplicate code
3368 view->setCurrentIndex(currentIndex);
3369 int currentRow = view->currentIndex().row();
3370 view->keyboardSearch(text);
3371 if (currentRow != view->currentIndex().row()) {
3372 setCurrentIndex(view->currentIndex());
3374 }
3375}
3376
3378{
3379 Q_Q(QComboBox);
3380
3382 sizeHint = QSize();
3384 q->updateGeometry();
3385 }
3386}
3387
3392{
3393 Q_D(QComboBox);
3394 if (d->lineEdit) {
3395 d->lineEdit->event(e);
3396 } else {
3397 if (!e->commitString().isEmpty())
3398 d->keyboardSearchString(e->commitString());
3399 else
3400 e->ignore();
3401 }
3402}
3403
3408{
3409 Q_D(const QComboBox);
3410 if (d->lineEdit)
3411 return d->lineEdit->inputMethodQuery(query);
3413}
3414
3418{
3419 Q_D(const QComboBox);
3420 if (d->lineEdit)
3421 return d->lineEdit->inputMethodQuery(query, argument);
3423}
3424
3465{
3466 Q_D(const QComboBox);
3467 return d->frame;
3468}
3469
3470
3472{
3473 Q_D(QComboBox);
3474 d->frame = enable;
3475 update();
3476 updateGeometry();
3477}
3478
3493{
3494 Q_D(const QComboBox);
3495 return d->modelColumn;
3496}
3497
3498void QComboBox::setModelColumn(int visibleColumn)
3499{
3500 Q_D(QComboBox);
3501 d->modelColumn = visibleColumn;
3502 QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());
3503 if (lv)
3504 lv->setModelColumn(visibleColumn);
3505#if QT_CONFIG(completer)
3506 if (d->lineEdit && d->lineEdit->completer())
3507 d->lineEdit->completer()->setCompletionColumn(visibleColumn);
3508#endif
3509 setCurrentIndex(currentIndex()); //update the text to the text of the new column;
3510}
3511
3513
3514#include "moc_qcombobox.cpp"
3515#include "moc_qcombobox_p.cpp"
The QAbstractItemDelegate class is used to display and edit data items from a model.
static QAbstractItemModel * staticEmptyModel()
virtual Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
virtual Q_INVOKABLE 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.
virtual Q_INVOKABLE 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.
The QAbstractItemView class provides the basic functionality for item view classes.
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
void setEditTriggers(EditTriggers triggers)
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
void setTextElideMode(Qt::TextElideMode mode)
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for this view and its model to delegate.
QModelIndex currentIndex() const
Returns the model index of the current item.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
void setIconSize(const QSize &size)
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
virtual Q_INVOKABLE QModelIndex mapToSource(const QModelIndex &proxyIndex) const =0
Reimplement this function to return the model index in the source model that corresponds to the proxy...
QAbstractItemModel * sourceModel
the source model of this proxy model.
SliderAction
\value SliderNoAction \value SliderSingleStepAdd \value SliderSingleStepSub \value SliderPageStepAdd ...
int minimum
the sliders's minimum value
int maximum
the slider's maximum value
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
static bool isEffectEnabled(Qt::UIEffect)
Returns true if effect is enabled; otherwise returns false.
static QPalette palette()
Returns the current application palette.
int doubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
int timerId() const noexcept
Returns the timer's ID.
Definition qbasictimer.h:35
void stop()
Stops the timer.
The QBoxLayout class lines up child widgets horizontally or vertically.
Definition qboxlayout.h:21
void invalidate() override
Resets cached information.
int count() const override
\reimp
QLayoutItem * itemAt(int) const override
\reimp
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtCore
Definition qbytearray.h:57
static bool isSeparator(const QModelIndex &index)
static void setSeparator(QAbstractItemModel *model, const QModelIndex &index)
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
QAbstractItemView * itemView() const
int spacing() const
Returns the spacing between the items in the view.
void scrollItemView(int action)
void mouseReleaseEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void showEvent(QShowEvent *e) override
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
void itemSelected(const QModelIndex &)
void hideEvent(QHideEvent *e) override
This event handler can be reimplemented in a subclass to receive widget hide events.
int topMargin() const
Returns the top/bottom vertical margin of the view.
void timerEvent(QTimerEvent *timerEvent) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void setItemView(QAbstractItemView *itemView)
Sets the item view to be used for the combobox popup.
QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)
void resizeEvent(QResizeEvent *e) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
bool eventFilter(QObject *o, QEvent *e) override
Filters events if this object has been installed as an event filter for the watched object.
void changeEvent(QEvent *e) override
This event handler can be reimplemented to handle state changes.
QStyleOptionComboBox comboStyleOption() const
void paintEvent(QPaintEvent *e) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void emitActivated(const QModelIndex &index)
QComboBox::InsertPolicy insertPolicy
QComboBoxPrivateContainer * viewContainer()
QStyle::SubControl hoverControl
void keyboardSearchString(const QString &text)
void updateViewContainerPaletteAndOpacity()
QComboBoxPrivateContainer * container
QPersistentModelIndex currentIndex
QStyle::SubControl newHoverControl(const QPoint &pos)
QLineEdit * lineEdit
QIcon itemIcon(const QModelIndex &index) const
QSize recomputeSizeHint(QSize &sh) const
void showPopupFromMouseEvent(QMouseEvent *e)
QPersistentModelIndex root
Qt::MatchFlags matchFlags() const
int itemRole() const
void _q_modelDestroyed()
QString placeholderText
int computeWidthHint() const
void setCurrentIndex(const QModelIndex &index)
QRect popupGeometry(const QPoint &globalPos) const
void updateArrow(QStyle::StateFlag state)
QAbstractItemModel * model
void _q_emitCurrentIndexChanged(const QModelIndex &index)
QComboBox::SizeAdjustPolicy sizeAdjustPolicy
QString itemText(const QModelIndex &index) const
void updateDelegate(bool force=false)
void adjustComboBoxSize()
void _q_rowsRemoved(const QModelIndex &parent, int start, int end)
void _q_updateIndexBeforeChange()
QStyle::StateFlag arrowState
void _q_itemSelected(const QModelIndex &item)
bool updateHoverControl(const QPoint &pos)
void updateCurrentText(const QString &text)
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void _q_editingFinished()
void updateLineEditGeometry()
void _q_emitHighlighted(const QModelIndex &index)
void updateLayoutDirection()
void _q_rowsInserted(const QModelIndex &parent, int start, int end)
void trySetValidIndex()
The QComboBox widget is a combined button and popup list.
Definition qcombobox.h:24
SizeAdjustPolicy sizeAdjustPolicy
the policy describing how the size of the combobox changes when the content changes
Definition qcombobox.h:36
void removeItem(int index)
Removes the item at the given index from the combobox.
void showEvent(QShowEvent *e) override
\reimp
InsertPolicy
This enum specifies what the QComboBox should do when a new string is entered by the user.
Definition qcombobox.h:67
@ InsertAtCurrent
Definition qcombobox.h:70
@ InsertAtTop
Definition qcombobox.h:69
@ InsertBeforeCurrent
Definition qcombobox.h:73
@ InsertAfterCurrent
Definition qcombobox.h:72
@ InsertAlphabetically
Definition qcombobox.h:74
@ InsertAtBottom
Definition qcombobox.h:71
void setInsertPolicy(InsertPolicy policy)
int maxCount
the maximum number of items allowed in the combobox
Definition qcombobox.h:34
QComboBox(QWidget *parent=nullptr)
Constructs a combobox with the given parent, using the default model QStandardItemModel.
void setModelColumn(int visibleColumn)
int modelColumn
the column in the model that is visible.
Definition qcombobox.h:42
QLineEdit * lineEdit() const
Returns the line edit used to edit items in the combobox, or \nullptr if there is no line edit.
QString itemText(int index) const
Returns the text for the given index in the combobox.
void setMinimumContentsLength(int characters)
virtual void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
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.
void setMaxCount(int max)
void setDuplicatesEnabled(bool enable)
SizeAdjustPolicy
This enum specifies how the size hint of the QComboBox should adjust when new content is added or con...
Definition qcombobox.h:81
@ AdjustToContents
Definition qcombobox.h:82
@ AdjustToMinimumContentsLengthWithIcon
Definition qcombobox.h:84
@ AdjustToContentsOnFirstShow
Definition qcombobox.h:83
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:230
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for the popup list view.
void mouseReleaseEvent(QMouseEvent *e) override
\reimp
int minimumContentsLength
the minimum number of characters that should fit into the combobox.
Definition qcombobox.h:37
bool editable
whether the combo box can be edited by the user
Definition qcombobox.h:27
void activated(int index)
This signal is sent when the user chooses an item in the combobox.
const QValidator * validator() const
Returns the validator that is used to constrain text input for the combobox.
QString placeholderText
Sets a placeholderText text shown when no valid index is set.
Definition qcombobox.h:39
int count
the number of items in the combobox
Definition qcombobox.h:28
bool event(QEvent *event) override
\reimp
void editTextChanged(const QString &)
This signal is emitted when the text in the combobox's line edit widget is changed.
void currentTextChanged(const QString &)
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by the popup list view.
virtual void hidePopup()
Hides the list of items in the combobox if it is currently visible and resets the internal state,...
void hideEvent(QHideEvent *e) override
\reimp
void setFrame(bool)
InsertPolicy insertPolicy
the policy used to determine where user-inserted items should appear in the combobox
Definition qcombobox.h:35
void setMaxVisibleItems(int maxItems)
void insertItems(int index, const QStringList &texts)
Inserts the strings from the list into the combobox as separate items, starting at the index specifie...
bool isEditable() const
void clearEditText()
Clears the contents of the line edit used for editing in the combobox.
virtual void setModel(QAbstractItemModel *model)
Sets the model to be model.
QModelIndex rootModelIndex() const
Returns the root model item index for the items in the combobox.
void inputMethodEvent(QInputMethodEvent *) override
\reimp
void keyPressEvent(QKeyEvent *e) override
\reimp
void setView(QAbstractItemView *itemView)
Sets the view to be used in the combobox popup to the given itemView.
void paintEvent(QPaintEvent *e) override
\reimp
void clear()
Clears the combobox, removing all items.
int maxVisibleItems
the maximum allowed size on screen of the combo box, measured in items
Definition qcombobox.h:33
void resizeEvent(QResizeEvent *e) override
\reimp
void setIconSize(const QSize &size)
void keyReleaseEvent(QKeyEvent *e) override
\reimp
QString currentText
the current text
Definition qcombobox.h:30
bool duplicatesEnabled
whether the user can enter duplicate items into the combobox
Definition qcombobox.h:40
void setEditText(const QString &text)
Sets the text in the combobox's text edit.
void setLineEdit(QLineEdit *edit)
Sets the line edit to use instead of the current line edit widget.
void setRootModelIndex(const QModelIndex &index)
Sets the root model item index for the items in the combobox.
QSize minimumSizeHint() const override
\reimp
QSize sizeHint() const override
\reimp
void setItemIcon(int index, const QIcon &icon)
Sets the icon for the item on the given index in the combobox.
void focusOutEvent(QFocusEvent *e) override
\reimp
QVariant itemData(int index, int role=Qt::UserRole) const
Returns the data for the given role in the given index in the combobox, or an invalid QVariant if the...
void changeEvent(QEvent *e) override
\reimp
void setSizeAdjustPolicy(SizeAdjustPolicy policy)
QAbstractItemModel * model() const
Returns the model used by the combobox.
void insertSeparator(int index)
void mousePressEvent(QMouseEvent *e) override
\reimp
int findText(const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Returns the index of the item containing the given text; otherwise returns -1.
Definition qcombobox.h:61
void setItemText(int index, const QString &text)
Sets the text for the item on the given index in the combobox.
void contextMenuEvent(QContextMenuEvent *e) override
\reimp
int currentIndex
the index of the current item in the combobox.
Definition qcombobox.h:31
QVariant currentData
the data for the current item
Definition qcombobox.h:32
virtual void showPopup()
Displays the list of items in the combobox.
void focusInEvent(QFocusEvent *e) override
\reimp
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.
QSize iconSize
the size of the icons shown in the combobox.
Definition qcombobox.h:38
void setCurrentText(const QString &text)
QIcon itemIcon(int index) const
Returns the icon for the given index in the combobox.
bool hasFrame() const
void setValidator(const QValidator *v)
Sets the validator to use instead of the current validator.
void setEditable(bool editable)
~QComboBox()
Destroys the combobox.
void setPlaceholderText(const QString &placeholderText)
QVariant inputMethodQuery(Qt::InputMethodQuery) const override
\reimp
void setCurrentIndex(int index)
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
When editing of an item starts, this function is called with the event that triggered the editing,...
QAbstractItemView * popup
static QCompleterPrivate * get(QCompleter *o)
The QCompleter class provides completions based on an item model.
Definition qcompleter.h:24
void setCompletionColumn(int column)
@ InlineCompletion
Definition qcompleter.h:40
@ UnfilteredPopupCompletion
Definition qcompleter.h:39
void setCompletionMode(CompletionMode mode)
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
void start() noexcept
Starts this timer.
\inmodule QtCore
Definition qcoreevent.h:45
@ EnabledChange
Definition qcoreevent.h:134
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ ShortcutOverride
Definition qcoreevent.h:158
@ StyleChange
Definition qcoreevent.h:136
@ FontChange
Definition qcoreevent.h:133
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ MouseButtonPress
Definition qcoreevent.h:60
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ PaletteChange
Definition qcoreevent.h:94
@ HoverMove
Definition qcoreevent.h:177
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ MacSizeChange
Definition qcoreevent.h:217
@ MouseButtonRelease
Definition qcoreevent.h:61
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:305
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant \inmodule QtGui
qreal height() const
Returns the height of the font.
\reentrant \inmodule QtGui
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...
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
\reentrant
Definition qfont.h:20
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
void setFrameStyle(int)
Sets the frame style to style.
Definition qframe.cpp:300
void paintEvent(QPaintEvent *) override
\reimp
Definition qframe.cpp:477
void setLineWidth(int)
Definition qframe.cpp:336
@ NoFrame
Definition qframe.h:39
void changeEvent(QEvent *) override
\reimp
Definition qframe.cpp:498
void setData(int key, const QVariant &value)
Sets this item's custom data for the key key to value.
void setEnabled(bool enabled)
If enabled is true, the item is enabled; otherwise, it is disabled.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
static QGuiApplicationPrivate * instance()
static QPlatformTheme * platformTheme()
static QStyleHints * styleHints()
Returns the application's style hints.
static QInputMethod * inputMethod()
returns the input method.
T value(const Key &key) const noexcept
Definition qhash.h:1044
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:585
\inmodule QtGui
Definition qevent.h:245
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:973
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
void reset()
Resets the input method state.
QModelIndexList selectedIndexes
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
\inmodule QtCore
The QKeyEvent class describes a key event.
Definition qevent.h:423
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1465
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
virtual QSpacerItem * spacerItem()
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned.
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
virtual void setSpacing(int)
Definition qlayout.cpp:266
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:994
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
bool event(QEvent *) override
\reimp
void selectAll()
Selects all the text (i.e.
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
void setText(const QString &)
void deselect()
Deselects any selected text.
QString text
the line edit's text.
Definition qlineedit.h:32
The QListView class provides a list or icon view onto a model.
Definition qlistview.h:17
int spacing
the space around the items in the layout
Definition qlistview.h:24
void setModelColumn(int column)
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void reserve(qsizetype size)
Definition qlist.h:746
void append(parameter_type t)
Definition qlist.h:441
void clear()
Definition qlist.h:417
Definition qmap.h:186
\inmodule QtCore
Definition qmargins.h:23
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:119
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:113
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore
constexpr int row() const noexcept
Returns the row this model index refers to.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
constexpr const QAbstractItemModel * model() const noexcept
Returns a pointer to the model containing the item that this index refers to.
Qt::ItemFlags flags() const
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
\inmodule QtGui
Definition qevent.h:195
QObject * parent
Definition qobject.h:61
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
\inmodule QtCore
Definition qobject.h:90
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
This is an overloaded function that will start a timer of type timerType and a timeout of interval mi...
Definition qobject.cpp:1792
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
Definition qobject.cpp:1518
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:64
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:150
@ Disabled
Definition qpalette.h:48
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
const QBrush & placeholderText() const
Definition qpalette.h:101
@ ButtonText
Definition qpalette.h:51
@ WindowText
Definition qpalette.h:50
bool isValid() const
Returns {true} if this persistent model index is valid; otherwise returns {false}.
int row() const
Returns the row this persistent model index refers to.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
virtual void setTag(quintptr tag)
The QPlatformTheme class allows customizing the UI based on themes.
virtual QPlatformMenuItem * createPlatformMenuItem() const
virtual QVariant themeHint(ThemeHint hint) const
virtual QPlatformMenu * createPlatformMenu() const
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:137
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr QPoint bottomLeft() const noexcept
Returns the position of the rectangle's bottom-left corner.
Definition qrect.h:229
constexpr void moveTopLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the top-left corner at the given position.
Definition qrect.h:303
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:372
constexpr void moveBottom(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate.
Definition qrect.h:297
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr void moveLeft(int pos) noexcept
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate.
Definition qrect.h:285
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:380
constexpr void moveBottomLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the bottom-left corner at the given position.
Definition qrect.h:321
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:223
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
Definition qrect.h:383
constexpr void moveTop(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
Definition qrect.h:288
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QList< QScreen * > virtualSiblings() const
Get the screen's virtual siblings.
Definition qscreen.cpp:357
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition qscrollbar.h:20
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:115
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr QSize boundedTo(const QSize &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition qsize.h:196
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:191
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:135
constexpr int & rwidth() noexcept
Returns a reference to the width.
Definition qsize.h:153
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:138
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
The QSpacerItem class provides blank space in a layout.
Definition qlayoutitem.h:57
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...
\inmodule QtCore
Definition qstack.h:13
T pop()
Removes the top item from the stack and returns it.
Definition qstack.h:18
void push(const T &t)
Adds element t to the top of the stack.
Definition qstack.h:17
The QStandardItemModel class provides a generic model for storing custom data.
The QStandardItem class provides an item for use with the QStandardItemModel class.
void insertRows(int row, const QList< QStandardItem * > &items)
Inserts items at row.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QString toLower() const &
Definition qstring.h:368
QChar * data()
Returns a pointer to the data stored in the QString.
Definition qstring.h:1095
The QStyleHintReturnMask class provides style hints that return a QRegion.
\variable QStyleOptionToolButton::features
\variable QStyleOptionProgressBar::minimum
MenuItemType menuItemType
The QStyleOption class stores the parameters used by QStyle functions.
QFontMetrics fontMetrics
QStyle::State state
QPalette palette
void initFrom(const QWidget *w)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
static bool useFullScreenForPopup()
Definition qstyle.cpp:2421
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition qstyle.h:65
@ State_Sunken
Definition qstyle.h:69
@ State_Active
Definition qstyle.h:83
@ State_Off
Definition qstyle.h:70
@ State_Enabled
Definition qstyle.h:67
@ State_On
Definition qstyle.h:72
@ State_Selected
Definition qstyle.h:82
@ State_None
Definition qstyle.h:66
@ CT_ComboBox
Definition qstyle.h:549
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=nullptr) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
@ SH_ComboBox_ListMouseTracking
Definition qstyle.h:602
@ SH_Menu_Mask
Definition qstyle.h:663
@ SH_ComboBox_Popup
Definition qstyle.h:608
@ SH_ComboBox_UseNativePopup
Definition qstyle.h:687
@ SH_Menu_FlashTriggeredItem
Definition qstyle.h:664
@ SH_ComboBox_PopupFrameStyle
Definition qstyle.h:652
@ SH_ComboBox_LayoutDirection
Definition qstyle.h:641
@ SH_ComboBox_AllowWheelScrolling
Definition qstyle.h:699
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ CE_ComboBoxLabel
Definition qstyle.h:221
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:2174
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=nullptr) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
@ PM_MenuVMargin
Definition qstyle.h:452
@ PM_SmallIconSize
Definition qstyle.h:493
@ CC_ComboBox
Definition qstyle.h:333
@ PE_PanelMenu
Definition qstyle.h:159
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_ComboBoxLayoutItem
Definition qstyle.h:290
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_All
Definition qstyle.h:400
@ SC_ComboBoxListBoxPopup
Definition qstyle.h:367
@ SC_None
Definition qstyle.h:348
@ SC_ComboBoxEditField
Definition qstyle.h:365
@ SC_ComboBoxArrow
Definition qstyle.h:366
The QTableView class provides a default model/view implementation of a table view.
Definition qtableview.h:18
bool showGrid
whether the grid is shown
Definition qtableview.h:20
\inmodule QtCore
Definition qcoreevent.h:359
void setSingleShot(bool singleShot)
Definition qtimer.cpp:580
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition qtimer.cpp:208
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition qtimer.cpp:156
bool singleShot
whether the timer is a single-shot timer
Definition qtimer.h:22
void stop()
Stops the timer.
Definition qtimer.cpp:226
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
QHeaderView * header() const
Returns the header for the tree view.
The QValidator class provides validation of input text.
Definition qvalidator.h:24
\inmodule QtCore
Definition qvariant.h:64
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
T value() const &
Definition qvariant.h:511
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:707
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
int userType() const
Definition qvariant.h:336
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool canConvert(QMetaType targetType) const
Definition qvariant.h:342
void setLayoutItemMargins(int left, int top, int right, int bottom)
uint inheritsInputMethodHints
Definition qwidget_p.h:722
static QRect screenGeometry(const QWidget *widget)
Definition qwidget_p.h:463
void update(T t)
static QRect availableScreenGeometry(const QWidget *widget)
Definition qwidget_p.h:468
QWindow * windowHandle(WindowHandleMode mode=WindowHandleMode::Direct) const
Definition qwidget.cpp:1029
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4320
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:886
void raise()
Raises this widget to the top of the parent widget's stack.
void setUpdatesEnabled(bool enable)
Definition qwidget.cpp:7940
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QSize minimumSize
the widget's minimum size
Definition qwidget.h:120
friend Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
void setWindowOpacity(qreal level)
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
void setPalette(const QPalette &)
Definition qwidget.cpp:4537
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QSize maximumSize
the widget's maximum size in pixels
Definition qwidget.h:121
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition qwidget.cpp:8789
bool updatesEnabled
whether updates are enabled
Definition qwidget.h:143
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition qwidget.cpp:9687
void hide()
Hides the widget.
Definition qwidget.cpp:8209
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9959
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
void setLayoutDirection(Qt::LayoutDirection direction)
Definition qwidget.cpp:4886
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7956
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8912
QStyle * style() const
Definition qwidget.cpp:2607
void setFont(const QFont &)
Definition qwidget.cpp:4674
QFont font
the font currently set for the widget
Definition qwidget.h:133
QRegion mask() const
Returns the mask currently set on a widget.
void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Creates a new widget window.
Definition qwidget.cpp:1129
bool hasFocus() const
Definition qwidget.cpp:6471
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9868
double windowOpacity
The level of opacity for the window.
Definition qwidget.h:154
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child,...
Definition qwidget.cpp:8868
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2503
void clearMask()
Removes any mask set by setMask().
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
QMargins contentsMargins() const
The contentsMargins function returns the widget's contents margins.
Definition qwidget.cpp:7740
void updateMicroFocus(Qt::InputMethodQuery query=Qt::ImQueryAll)
Updates the widget's micro focus and informs input methods that the state specified by query has chan...
virtual void showEvent(QShowEvent *event)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
\inmodule QtGui
Definition qwindow.h:63
void setMinimumWidth(int w)
Definition qwindow.cpp:1647
#define this
Definition dialogs.cpp:9
QOpenGLWidget * widget
[1]
QString text
void textChanged(const QString &newText)
double e
uint alignment
QStyleOptionButton opt
fontMetrics
else opt state
[0]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
void setter(QUntypedPropertyData *d, const void *value)
CheckState
@ Unchecked
@ Checked
InputMethodQuery
@ AlignRight
Definition qnamespace.h:145
@ LeftButton
Definition qnamespace.h:57
@ WA_MacMiniSize
Definition qnamespace.h:362
@ WA_WindowPropagation
Definition qnamespace.h:348
@ WA_Resized
Definition qnamespace.h:307
@ WA_Hover
Definition qnamespace.h:339
@ WA_DontShowOnScreen
Definition qnamespace.h:382
@ WA_X11NetWmWindowTypeCombo
Definition qnamespace.h:396
@ WA_NoMouseReplay
Definition qnamespace.h:319
@ WA_MacShowFocusRect
Definition qnamespace.h:358
@ WA_SetFont
Definition qnamespace.h:303
@ WA_MacSmallSize
Definition qnamespace.h:361
@ WA_InputMethodEnabled
Definition qnamespace.h:294
LayoutDirection
@ WheelFocus
Definition qnamespace.h:110
@ TabFocus
Definition qnamespace.h:107
@ FontRole
@ TextAlignmentRole
@ ForegroundRole
@ UserRole
@ DecorationRole
@ BackgroundRole
@ EditRole
@ CheckStateRole
@ DisplayRole
@ UI_AnimateCombo
@ Key_Escape
Definition qnamespace.h:658
@ Key_Select
@ Key_Return
Definition qnamespace.h:662
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_PageUp
Definition qnamespace.h:676
@ Key_Space
Definition qnamespace.h:512
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_F4
Definition qnamespace.h:688
@ Key_PageDown
Definition qnamespace.h:677
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_End
Definition qnamespace.h:671
ScrollBarPolicy
@ ScrollBarAlwaysOff
@ ScrollBarAlwaysOn
@ ScrollBarAsNeeded
@ ControlModifier
@ AltModifier
@ CaseInsensitive
@ CaseSensitive
@ UniqueConnection
ContextMenuPolicy
@ DefaultContextMenu
@ NoContextMenu
@ ElideMiddle
Definition qnamespace.h:190
@ ItemIsUserCheckable
@ ItemIsSelectable
@ ItemIsEnabled
@ MatchCaseSensitive
@ MatchFixedString
FontHash * qt_app_fonts_hash()
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define qApp
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
Definition qeffects.cpp:524
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_CATCH(A)
#define QT_TRY
#define qWarning
Definition qlogging.h:162
int qCeil(T v)
Definition qmath.h:36
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLuint64 key
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLint GLsizei width
GLint GLint bottom
GLbitfield flags
GLboolean enable
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
struct _cl_event * event
GLenum query
const GLubyte * c
GLsizei maxCount
Definition qopenglext.h:677
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLint GLenum GLboolean normalized
Definition qopenglext.h:752
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
static QPlatformTheme::Font platformFont(QQuickTheme::Scope scope)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
#define emit
#define Q_UNUSED(x)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
size_t quintptr
Definition qtypes.h:72
const char className[16]
[1]
Definition qwizard.cpp:100
QSqlQueryModel * model
[16]
QList< int > list
[14]
QList< QChar > characters
QList< int > vector
[14]
obj metaObject() -> className()
myObject disconnect()
[26]
QVariant variant
[1]
QString dir
[11]
QGraphicsItem * item
edit isVisible()
QItemSelection * selection
[0]
QList< QTreeWidgetItem * > items
QPointer< QLineEdit > le
widget render & pixmap
QPainter painter(this)
[7]
QFrame frame
[0]
lineEdit setCompleter(completer)
QCompleter * completer
[0]
QMenu menu
[5]
QSizePolicy policy
QNetworkProxy proxy
[0]
QQuickView * view
[0]
QDBusArgument argument
bool contains(const AT &t) const noexcept
Definition qlist.h:44
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
virtual HRESULT STDMETHODCALLTYPE Move(enum TextUnit unit, int count, __RPC__out int *pRetVal)=0