Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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#include <array>
52
53#include <QtCore/qpointer.h>
54
56
57using namespace Qt::StringLiterals;
58
61 shownOnce(false),
62 duplicatesEnabled(false),
63 frame(true),
64 inserting(false),
65 hidingPopup(false)
66{
67}
68
70{
72#ifdef Q_OS_MAC
73 cleanupNativePopup();
74#endif
75}
76
77QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,
78 const QModelIndex &index) const
79{
80 QStyleOptionMenuItem menuOption;
81
82 QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));
84 if (value.canConvert<QBrush>()) {
85 resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));
86 resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));
87 resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
88 }
89 menuOption.palette = resolvedpalette;
90 menuOption.state = QStyle::State_None;
91 if (mCombo->window()->isActiveWindow())
92 menuOption.state = QStyle::State_Active;
93 if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
94 menuOption.state |= QStyle::State_Enabled;
95 else
96 menuOption.palette.setCurrentColorGroup(QPalette::Disabled);
98 menuOption.state |= QStyle::State_Selected;
99 menuOption.checkType = QStyleOptionMenuItem::NonExclusive;
100 // a valid checkstate means that the model has checkable items
102 if (!checkState.isValid()) {
103 menuOption.checked = mCombo->currentIndex() == index.row();
104 } else {
105 menuOption.checked = qvariant_cast<int>(checkState) == Qt::Checked;
106 menuOption.state |= qvariant_cast<int>(checkState) == Qt::Checked
108 }
110 menuOption.menuItemType = QStyleOptionMenuItem::Separator;
111 else
112 menuOption.menuItemType = QStyleOptionMenuItem::Normal;
113
115 switch (variant.userType()) {
116 case QMetaType::QIcon:
117 menuOption.icon = qvariant_cast<QIcon>(variant);
118 break;
119 case QMetaType::QColor: {
120 static QPixmap pixmap(option.decorationSize);
121 pixmap.fill(qvariant_cast<QColor>(variant));
122 menuOption.icon = pixmap;
123 break; }
124 default:
125 menuOption.icon = qvariant_cast<QPixmap>(variant);
126 break;
127 }
128 if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
129 menuOption.palette.setBrush(QPalette::All, QPalette::Window,
130 qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
131 }
132 menuOption.text = index.model()->data(index, Qt::DisplayRole).toString().replace(u'&', "&&"_L1);
133 menuOption.reservedShortcutWidth = 0;
134 menuOption.maxIconWidth = option.decorationSize.width() + 4;
135 menuOption.menuRect = option.rect;
136 menuOption.rect = option.rect;
137
138 // Make sure fonts set on the model or on the combo box, in
139 // that order, also override the font for the popup menu.
140 QVariant fontRoleData = index.data(Qt::FontRole);
141 if (fontRoleData.isValid()) {
142 menuOption.font = qvariant_cast<QFont>(fontRoleData);
143 } else if (mCombo->testAttribute(Qt::WA_SetFont)
146 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) {
147 menuOption.font = mCombo->font();
148 } else {
149 menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
150 }
151
152 menuOption.fontMetrics = QFontMetrics(menuOption.font);
153
154 return menuOption;
155}
156
158 const QStyleOptionViewItem &option, const QModelIndex &index)
159{
162
163 // make sure that the item is checkable
164 Qt::ItemFlags flags = model->flags(index);
166 || !(flags & Qt::ItemIsEnabled))
167 return false;
168
169 // make sure that we have a check state
171 if (!checkState.isValid())
172 return false;
173
174 // make sure that we have the right event type
175 if ((event->type() == QEvent::MouseButtonRelease)
176 || (event->type() == QEvent::MouseButtonDblClick)
177 || (event->type() == QEvent::MouseButtonPress)) {
178 QMouseEvent *me = static_cast<QMouseEvent*>(event);
179 if (me->button() != Qt::LeftButton)
180 return false;
181
182 if ((event->type() == QEvent::MouseButtonPress)
183 || (event->type() == QEvent::MouseButtonDblClick)) {
184 pressedIndex = index.row();
185 return false;
186 }
187
188 if (index.row() != pressedIndex)
189 return false;
190 pressedIndex = -1;
191
192 } else if (event->type() == QEvent::KeyPress) {
193 if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space
194 && static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select)
195 return false;
196 } else {
197 return false;
198 }
199
200 // we don't support user-tristate items in QComboBox (not implemented in any style)
204}
205
206#if QT_CONFIG(completer)
207void QComboBoxPrivate::completerActivated(const QModelIndex &index)
208{
209 Q_Q(QComboBox);
210#if QT_CONFIG(proxymodel)
211 if (index.isValid() && q->completer()) {
212 QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());
213 if (proxy) {
214 const QModelIndex &completerIndex = proxy->mapToSource(index);
215 int row = -1;
216 if (completerIndex.model() == model) {
217 row = completerIndex.row();
218 } else {
219 // if QCompleter uses a proxy model to host widget's one - map again
220 QAbstractProxyModel *completerProxy = qobject_cast<QAbstractProxyModel *>(q->completer()->model());
221 if (completerProxy && completerProxy->sourceModel() == model) {
222 row = completerProxy->mapToSource(completerIndex).row();
223 } else {
224 QString match = q->completer()->model()->data(completerIndex).toString();
225 row = q->findText(match, matchFlags());
226 }
227 }
228 q->setCurrentIndex(row);
230 }
231 }
232#endif
233}
234#endif // QT_CONFIG(completer)
235
237{
238 Q_Q(QComboBox);
239 if (arrowState == state)
240 return;
243 q->initStyleOption(&opt);
244 q->update(q->rect());
245}
246
248{
249 Q_Q(QComboBox);
250 if (lineEdit) {
253 }
255 modelChanged();
256 q->update();
257}
258
263
265{
266 Q_Q(QComboBox);
267 bool currentReset = false;
268
269 const int rowCount = q->count();
270 for (int pos = 0; pos < rowCount; ++pos) {
271 const QModelIndex idx(model->index(pos, modelColumn, root));
272 if (idx.flags() & Qt::ItemIsEnabled) {
273 setCurrentIndex(idx);
274 currentReset = true;
275 break;
276 }
277 }
278
279 if (!currentReset)
281}
282
283QRect QComboBoxPrivate::popupGeometry(const QPoint &globalPosition) const
284{
285 Q_Q(const QComboBox);
287 ? QWidgetPrivate::screenGeometry(q, globalPosition)
289}
290
292{
293
294 Q_Q(QComboBox);
295 QRect lastHoverRect = hoverRect;
296 QStyle::SubControl lastHoverControl = hoverControl;
297 bool doesHover = q->testAttribute(Qt::WA_Hover);
298 if (lastHoverControl != newHoverControl(pos) && doesHover) {
299 q->update(lastHoverRect);
300 q->update(hoverRect);
301 return true;
302 }
303 return !doesHover;
304}
305
307{
308 Q_Q(QComboBox);
310 q->initStyleOption(&opt);
311 opt.subControls = QStyle::SC_All;
312 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);
314 ? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)
315 : QRect();
316 return hoverControl;
317}
318
319/*
320 Computes a size hint based on the maximum width
321 for the items in the combobox.
322*/
324{
325 Q_Q(const QComboBox);
326
327 int width = 0;
328 const int count = q->count();
329 const int iconWidth = q->iconSize().width() + 4;
330 const QFontMetrics &fontMetrics = q->fontMetrics();
331
332 for (int i = 0; i < count; ++i) {
333 const int textWidth = fontMetrics.horizontalAdvance(q->itemText(i));
334 if (q->itemIcon(i).isNull())
335 width = (qMax(width, textWidth));
336 else
337 width = (qMax(width, textWidth + iconWidth));
338 }
339
341 q->initStyleOption(&opt);
342 QSize tmp(width, 0);
343 tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);
344 return tmp.width();
345}
346
348{
349 Q_Q(const QComboBox);
350 if (!sh.isValid()) {
352 int count = q->count();
353 QSize iconSize = q->iconSize();
354 const QFontMetrics &fm = q->fontMetrics();
355
356 // text width
357 if (&sh == &sizeHint || minimumContentsLength == 0) {
358 switch (sizeAdjustPolicy) {
361 if (count == 0) {
362 sh.rwidth() = 7 * fm.horizontalAdvance(u'x');
363 } else {
364 for (int i = 0; i < count; ++i) {
365 if (!q->itemIcon(i).isNull()) {
366 hasIcon = true;
367 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));
368 } else {
369 sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));
370 }
371 }
372 }
373 break;
375 ;
376 }
377 } else {
378 for (int i = 0; i < count && !hasIcon; ++i)
379 hasIcon = !q->itemIcon(i).isNull();
380 }
381 if (minimumContentsLength > 0)
382 sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.horizontalAdvance(u'X') + (hasIcon ? iconSize.width() + 4 : 0)));
384 sh.setWidth(qMax(sh.width(), fm.boundingRect(placeholderText).width()));
385
386
387 // height
388 sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);
389 if (hasIcon) {
390 sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
391 }
392
393 // add style and strut values
395 q->initStyleOption(&opt);
396 sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);
397 }
398 return sh;
399}
400
405
418
419
421{
422 if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
425 combo->updateGeometry();
426 combo->adjustSize();
427 combo->update();
428 }
429 }
430}
431
433{
435 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
436 QStyleOption myOpt;
437 myOpt.initFrom(this);
439 if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
440 setMask(mask.region);
441 }
442 } else {
443 clearMask();
444 }
446}
447
449{
451 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &cbOpt, combo)
452 && mask().isEmpty()) {
454 opt.initFrom(this);
455 QPainter p(this);
457 }
458
460}
461
463 : QFrame(parent, Qt::Popup), combo(parent)
464{
465 // we need the combobox and itemview
468
471
472 // setup container
474
475 // we need a vertical layout
477 layout->setSpacing(0);
479
480 // set item view
482
483 // add scroller arrows if style needs them
485 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
486 if (usePopup) {
489 top->hide();
490 bottom->hide();
491 } else {
492 setLineWidth(1);
493 }
494
495 if (top) {
496 layout->insertWidget(0, top);
499 }
500 if (bottom) {
504 }
505
506 // Some styles (Mac) have a margin at the top and bottom of the popup.
507 layout->insertSpacing(0, 0);
508 layout->addSpacing(0);
510}
511
517
519{
520#if QT_CONFIG(scrollbar)
521 if (view->verticalScrollBar())
522 view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
523#endif
524}
525
527{
528 if (top)
529 top->hide();
530 if (bottom)
531 bottom->hide();
532}
533
534/*
535 Hides or shows the scrollers when we emulate a popupmenu
536*/
538{
539#if QT_CONFIG(scrollbar)
540 if (!top || !bottom)
541 return;
542
543 if (isVisible() == false)
544 return;
545
547 if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&
548 view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
549
550 bool needTop = view->verticalScrollBar()->value()
551 > (view->verticalScrollBar()->minimum() + topMargin());
552 bool needBottom = view->verticalScrollBar()->value()
553 < (view->verticalScrollBar()->maximum() - bottomMargin() - topMargin());
554 if (needTop)
555 top->show();
556 else
557 top->hide();
558 if (needBottom)
559 bottom->show();
560 else
561 bottom->hide();
562 } else {
563 top->hide();
564 bottom->hide();
565 }
566#endif // QT_CONFIG(scrollbar)
567}
568
569/*
570 Cleans up when the view is destroyed.
571*/
573{
574 view = nullptr;
576}
577
578/*
579 Returns the item view used for the combobox popup.
580*/
582{
583 return view;
584}
585
590{
592
593 // clean up old one
594 if (view) {
595 view->removeEventFilter(this);
596 view->viewport()->removeEventFilter(this);
597#if QT_CONFIG(scrollbar)
598 disconnect(view->verticalScrollBar(), &QScrollBar::valueChanged,
600 disconnect(view->verticalScrollBar(), &QScrollBar::rangeChanged,
602#endif
603 disconnect(view, &QAbstractItemView::destroyed,
605
606 if (isAncestorOf(view))
607 delete view;
608 view = nullptr;
609 }
610
611 // setup the item view
612 view = itemView;
613 view->setParent(this);
614 view->setAttribute(Qt::WA_MacShowFocusRect, false);
615 qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);
616 view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
617 view->installEventFilter(this);
618 view->viewport()->installEventFilter(this);
619 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
621 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
622#if QT_CONFIG(scrollbar)
623 if (usePopup)
624 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
625#endif
627 usePopup) {
628 view->setMouseTracking(true);
629 }
631 view->setFrameStyle(QFrame::NoFrame);
632 view->setLineWidth(0);
634#if QT_CONFIG(scrollbar)
635 connect(view->verticalScrollBar(), &QScrollBar::valueChanged,
637 connect(view->verticalScrollBar(), &QScrollBar::rangeChanged,
639#endif
640 connect(view, &QAbstractItemView::destroyed,
642}
643
648{
649 if (const QListView *lview = qobject_cast<const QListView*>(view))
650 return lview->spacing();
651#if QT_CONFIG(tableview)
652 if (const QTableView *tview = qobject_cast<const QTableView*>(view))
653 return tview->showGrid() ? 1 : 0;
654#endif
655 return 0;
656}
657
662{
663 QListView *lview = qobject_cast<QListView*>(view);
664 if (lview)
665 return 2 * lview->spacing(); // QListView::spacing is the padding around the item.
666#if QT_CONFIG(tableview)
667 QTableView *tview = qobject_cast<QTableView*>(view);
668 if (tview)
669 return tview->showGrid() ? 1 : 0;
670#endif
671 return 0;
672}
673
675{
676 if (!layout() || layout()->count() < 1)
677 return;
678
679 QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());
680 if (!boxLayout)
681 return;
682
684 const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
685 const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
686
687 QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();
688 if (topSpacer)
689 topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
690
691 QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();
692 if (bottomSpacer && bottomSpacer != topSpacer)
693 bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
694
695 boxLayout->invalidate();
696}
697
699{
700 // add scroller arrows if style needs them
702 view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
703 combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));
706}
707
715
716
718{
719 switch (e->type()) {
721 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);
722 switch (keyEvent->key()) {
723 case Qt::Key_Enter:
724 case Qt::Key_Return:
725#ifdef QT_KEYPAD_NAVIGATION
726 case Qt::Key_Select:
727#endif
728 if (view->currentIndex().isValid() && view->currentIndex().flags().testFlag(Qt::ItemIsEnabled)) {
729 combo->hidePopup();
730 keyEvent->accept();
732 }
733 return true;
734 case Qt::Key_Down:
735 if (!(keyEvent->modifiers() & Qt::AltModifier))
736 break;
738 case Qt::Key_F4:
739 combo->hidePopup();
740 keyEvent->accept();
742 return true;
743 default:
744#if QT_CONFIG(shortcut)
745 if (keyEvent->matches(QKeySequence::Cancel) && isVisible()) {
746 keyEvent->accept();
747 return true;
748 }
749#endif
750 break;
751 }
752 break;
753 }
755 if (isVisible()) {
756 QMouseEvent *m = static_cast<QMouseEvent *>(e);
757 QWidget *widget = static_cast<QWidget *>(o);
758 QPoint vector = widget->mapToGlobal(m->position().toPoint()) - initialClickPosition;
759 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
761 QModelIndex indexUnderMouse = view->indexAt(m->position().toPoint());
762 if (indexUnderMouse.isValid()
763 && !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
764 view->setCurrentIndex(indexUnderMouse);
765 }
766 }
767 break;
769 maybeIgnoreMouseButtonRelease = false;
770 break;
772 bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
773
774 QMouseEvent *m = static_cast<QMouseEvent *>(e);
775 if (isVisible() && view->rect().contains(m->position().toPoint()) && view->currentIndex().isValid()
776 && !blockMouseReleaseTimer.isActive() && !ignoreEvent
777 && (view->currentIndex().flags().testFlag(Qt::ItemIsEnabled))
778 && (view->currentIndex().flags().testFlag(Qt::ItemIsSelectable))) {
779 combo->hidePopup();
781 return true;
782 }
783 break;
784 }
785 default:
786 break;
787 }
788 return QFrame::eventFilter(o, e);
789}
790
795
797{
799 combo->update();
800#if QT_CONFIG(graphicsview)
801 // QGraphicsScenePrivate::removePopup closes the combo box popup, it hides it non-explicitly.
802 // Hiding/showing the QComboBox after this will unexpectedly show the popup as well.
803 // Re-hiding the popup container makes sure it is explicitly hidden.
804 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget())
805 proxy->hide();
806#endif
807}
808
810{
811
813 opt.subControls = QStyle::SC_All;
814 opt.activeSubControls = QStyle::SC_ComboBoxArrow;
816 combo->mapFromGlobal(e->globalPosition().toPoint()),
817 combo);
818 if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
819 || (!combo->isEditable() && sc != QStyle::SC_None))
821 combo->hidePopup();
822}
823
832
834{
835 // ### This should use QComboBox's initStyleOption(), but it's protected
836 // perhaps, we could cheat by having the QCombo private instead?
838 opt.initFrom(combo);
839 opt.subControls = QStyle::SC_All;
840 opt.activeSubControls = QStyle::SC_None;
841 opt.editable = combo->isEditable();
842 return opt;
843}
844
934 : QWidget(*new QComboBoxPrivate(), parent, { })
935{
936 Q_D(QComboBox);
937 d->init();
938}
939
944 : QWidget(dd, parent, { })
945{
946 Q_D(QComboBox);
947 d->init();
948}
949
1035{
1036 Q_Q(QComboBox);
1037#ifdef Q_OS_MACOS
1038 // On OS X, only line edits and list views always get tab focus. It's only
1039 // when we enable full keyboard access that other controls can get tab focus.
1040 // When it's not editable, a combobox looks like a button, and it behaves as
1041 // such in this respect.
1042 if (!q->isEditable())
1043 q->setFocusPolicy(Qt::TabFocus);
1044 else
1045#endif
1046 q->setFocusPolicy(Qt::WheelFocus);
1047
1051 q->setModel(new QStandardItemModel(0, 1, q));
1052 if (!q->isEditable())
1053 q->setAttribute(Qt::WA_InputMethodEnabled, false);
1054 else
1055 q->setAttribute(Qt::WA_InputMethodEnabled);
1056}
1057
1081
1082
1087
1088void QComboBoxPrivate::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
1089{
1090 Q_Q(QComboBox);
1091 if (inserting || topLeft.parent() != root)
1092 return;
1093
1095 sizeHint = QSize();
1097 q->updateGeometry();
1098 }
1099
1100 if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
1101 const QString text = q->itemText(currentIndex.row());
1102 if (lineEdit) {
1105 } else {
1107 }
1108 q->update();
1109#if QT_CONFIG(accessibility)
1110 QAccessibleValueChangeEvent event(q, text);
1111 QAccessible::updateAccessibility(&event);
1112#endif
1113 }
1114}
1115
1117{
1118 Q_Q(QComboBox);
1119 if (inserting || parent != root)
1120 return;
1121
1123 sizeHint = QSize();
1125 q->updateGeometry();
1126 }
1127
1128 // set current index if combo was previously empty and there is no placeholderText
1129 if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid() &&
1131#if QT_CONFIG(accessibility)
1132 // This might have been called by the model emitting rowInserted(), at which
1133 // point the view won't have updated the accessibility bridge yet about its new
1134 // dimensions. Do it now so that the change of the selection matches the row
1135 // indexes of the accessibility bridge's representation.
1136 if (container && container->itemView()) {
1137 QAccessibleTableModelChangeEvent event(container->itemView(),
1138 QAccessibleTableModelChangeEvent::ModelReset);
1139 QAccessible::updateAccessibility(&event);
1140 }
1141#endif
1142 q->setCurrentIndex(0);
1143 // need to emit changed if model updated index "silently"
1144 } else if (currentIndex.row() != indexBeforeChange) {
1145 q->update();
1147 }
1148}
1149
1154
1155void QComboBoxPrivate::rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/)
1156{
1157 Q_Q(QComboBox);
1158 if (parent != root)
1159 return;
1160
1162 sizeHint = QSize();
1164 q->updateGeometry();
1165 }
1166
1167 // model has removed the last row
1168 if (model->rowCount(root) == 0) {
1170 return;
1171 }
1172
1173 // model has changed the currentIndex
1175 if (!currentIndex.isValid() && q->count()) {
1176 q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));
1177 return;
1178 }
1179 if (lineEdit) {
1180 lineEdit->setText(q->itemText(currentIndex.row()));
1182 }
1183 q->update();
1185 }
1186}
1187
1188
1190{
1191 if (!container)
1192 return;
1193 Q_Q(QComboBox);
1195 q->initStyleOption(&opt);
1196#if QT_CONFIG(menu)
1197 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1198 QMenu menu;
1202 } else
1203#endif
1204 {
1205 container->setPalette(q->palette());
1207 }
1208 if (lineEdit)
1209 lineEdit->setPalette(q->palette());
1210}
1211
1213{
1214#ifdef Q_OS_MACOS
1215 Q_Q(QComboBox);
1216
1217 // See comment in QComboBoxPrivate::init()
1218 if (q->isEditable())
1219 q->setFocusPolicy(Qt::WheelFocus);
1220 else
1221 q->setFocusPolicy(Qt::TabFocus);
1222#endif
1223}
1224
1233{
1234 if (!option)
1235 return;
1236
1237 Q_D(const QComboBox);
1238 option->initFrom(this);
1239 option->editable = isEditable();
1240 option->frame = d->frame;
1241 if (hasFocus() && !option->editable)
1243 option->subControls = QStyle::SC_All;
1244 if (d->arrowState == QStyle::State_Sunken) {
1245 option->activeSubControls = QStyle::SC_ComboBoxArrow;
1246 option->state |= d->arrowState;
1247 } else {
1248 option->activeSubControls = d->hoverControl;
1249 }
1250 option->currentText = currentText();
1251 if (d->currentIndex.isValid()) {
1252 option->currentIcon = d->itemIcon(d->currentIndex);
1253 QVariant alignment = d->model->data(d->currentIndex, Qt::TextAlignmentRole);
1254 if (alignment.isValid())
1255 option->textAlignment = static_cast<Qt::Alignment>(alignment.toUInt());
1256 }
1257 option->iconSize = iconSize();
1258 if (d->container && d->container->isVisible())
1259 option->state |= QStyle::State_On;
1260}
1261
1263{
1264 if (!lineEdit)
1265 return;
1266
1267 Q_Q(QComboBox);
1269 q->initStyleOption(&opt);
1270 QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,
1272 if (!q->itemIcon(q->currentIndex()).isNull()) {
1273 QRect comboRect(editRect);
1274 editRect.setWidth(editRect.width() - q->iconSize().width() - 4);
1275 editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,
1276 editRect.size(), comboRect);
1277 }
1278 lineEdit->setGeometry(editRect);
1279}
1280
1281Qt::MatchFlags QComboBoxPrivate::matchFlags() const
1282{
1283 // Base how duplicates are determined on the autocompletion case sensitivity
1284 Qt::MatchFlags flags = Qt::MatchFixedString;
1285#if QT_CONFIG(completer)
1286 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)
1287#endif
1289 return flags;
1290}
1291
1292
1294{
1295 Q_Q(QComboBox);
1296 if (!lineEdit)
1297 return;
1298 const auto leText = lineEdit->text();
1299 if (!leText.isEmpty() && itemText(currentIndex) != leText) {
1300#if QT_CONFIG(completer)
1301 const auto *leCompleter = lineEdit->completer();
1302 const auto *popup = leCompleter ? QCompleterPrivate::get(leCompleter)->popup : nullptr;
1303 if (popup && popup->isVisible()) {
1304 // QLineEdit::editingFinished() will be emitted before the code flow returns
1305 // to QCompleter::eventFilter(), where QCompleter::activated() may be emitted.
1306 // We know that the completer popup will still be visible at this point, and
1307 // that any selection should be valid.
1308 const QItemSelectionModel *selModel = popup->selectionModel();
1309 const QModelIndex curIndex = popup->currentIndex();
1310 const bool completerIsActive = selModel && selModel->selectedIndexes().contains(curIndex);
1311
1312 if (completerIsActive)
1313 return;
1314 }
1315#endif
1316 const int index = q_func()->findText(leText, matchFlags());
1317 if (index != -1) {
1318 q->setCurrentIndex(index);
1320 }
1321 }
1322
1323}
1324
1326{
1327 Q_Q(QComboBox);
1328
1329 // The insertion code below does not apply when the policy is QComboBox::NoInsert.
1330 // In case a completer is installed, item activation via the completer is handled
1331 // in completerActivated(). Otherwise editingFinished() updates the current
1332 // index as appropriate.
1334 return;
1335
1336 if (lineEdit && !lineEdit->text().isEmpty()) {
1337 if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
1338 return;
1339 lineEdit->deselect();
1340 lineEdit->end(false);
1342 // check for duplicates (if not enabled) and quit
1343 int index = -1;
1344 if (!duplicatesEnabled) {
1345 index = q->findText(text, matchFlags());
1346 if (index != -1) {
1347 q->setCurrentIndex(index);
1349 return;
1350 }
1351 }
1352 switch (insertPolicy) {
1354 index = 0;
1355 break;
1357 index = q->count();
1358 break;
1362 if (!q->count() || !currentIndex.isValid())
1363 index = 0;
1365 q->setItemText(q->currentIndex(), text);
1367 index = q->currentIndex() + 1;
1369 index = q->currentIndex();
1370 break;
1372 index = 0;
1373 for (int i = 0; i < q->count(); ++i, ++index) {
1374 if (text.toLower() < q->itemText(i).toLower())
1375 break;
1376 }
1377 break;
1378 default:
1379 break;
1380 }
1381 if (index >= 0) {
1382 q->insertItem(index, text);
1383 q->setCurrentIndex(index);
1385 }
1386 }
1387}
1388
1390{
1391 Q_Q(QComboBox);
1392 if (item != currentIndex) {
1394 } else if (lineEdit) {
1396 lineEdit->setText(q->itemText(currentIndex.row()));
1397 }
1399}
1400
1402{
1403 Q_Q(QComboBox);
1404 if (!index.isValid())
1405 return;
1407 emit q->activated(index.row());
1408 emit q->textActivated(text);
1409}
1410
1412{
1413 Q_Q(QComboBox);
1414 if (!index.isValid())
1415 return;
1417 emit q->highlighted(index.row());
1418 emit q->textHighlighted(text);
1419}
1420
1422{
1423 Q_Q(QComboBox);
1424 const QString text = itemText(index);
1425 emit q->currentIndexChanged(index.row());
1426 // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
1427 if (!lineEdit)
1429#if QT_CONFIG(accessibility)
1430 QAccessibleValueChangeEvent event(q, text);
1431 QAccessible::updateAccessibility(&event);
1432#endif
1433}
1434
1436{
1437 return index.isValid() ? model->data(index, itemRole()).toString() : QString();
1438}
1439
1441{
1442 return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
1443}
1444
1449{
1450 // ### check delegateparent and delete delegate if us?
1451 Q_D(QComboBox);
1452
1453 QT_TRY {
1454 d->disconnectModel();
1455 } QT_CATCH(...) {
1456 ; // objects can't throw in destructor
1457 }
1458
1459 // Dispose of container before QComboBox goes away
1460 delete d->container;
1461}
1462
1473{
1474 Q_D(const QComboBox);
1475 return d->maxVisibleItems;
1476}
1477
1479{
1480 Q_D(QComboBox);
1481 if (Q_UNLIKELY(maxItems < 0)) {
1482 qWarning("QComboBox::setMaxVisibleItems: "
1483 "Invalid max visible items (%d) must be >= 0", maxItems);
1484 return;
1485 }
1486 d->maxVisibleItems = maxItems;
1487}
1488
1496{
1497 Q_D(const QComboBox);
1498 return d->model->rowCount(d->root);
1499}
1500
1514{
1515 Q_D(QComboBox);
1516 if (Q_UNLIKELY(max < 0)) {
1517 qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
1518 return;
1519 }
1520
1521 const int rowCount = count();
1522 if (rowCount > max)
1523 d->model->removeRows(max, rowCount - max, d->root);
1524
1525 d->maxCount = max;
1526}
1527
1529{
1530 Q_D(const QComboBox);
1531 return d->maxCount;
1532}
1533
1544{
1545 Q_D(const QComboBox);
1546 return d->duplicatesEnabled;
1547}
1548
1550{
1551 Q_D(QComboBox);
1552 d->duplicatesEnabled = enable;
1553}
1554
1569int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const
1570{
1571 Q_D(const QComboBox);
1572 QModelIndex start = d->model->index(0, d->modelColumn, d->root);
1573 const QModelIndexList result = d->model->match(start, role, data, 1, flags);
1574 if (result.isEmpty())
1575 return -1;
1576 return result.first().row();
1577}
1578
1591{
1592 Q_D(const QComboBox);
1593 return d->insertPolicy;
1594}
1595
1597{
1598 Q_D(QComboBox);
1599 d->insertPolicy = policy;
1600}
1601
1613{
1614 Q_D(const QComboBox);
1615 return d->sizeAdjustPolicy;
1616}
1617
1619{
1620 Q_D(QComboBox);
1621 if (policy == d->sizeAdjustPolicy)
1622 return;
1623
1624 d->sizeAdjustPolicy = policy;
1625 d->sizeHint = QSize();
1626 d->adjustComboBoxSize();
1628}
1629
1642{
1643 Q_D(const QComboBox);
1644 return d->minimumContentsLength;
1645}
1646
1648{
1649 Q_D(QComboBox);
1650 if (characters == d->minimumContentsLength || characters < 0)
1651 return;
1652
1653 d->minimumContentsLength = characters;
1654
1655 if (d->sizeAdjustPolicy == AdjustToContents
1656 || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
1657 d->sizeHint = QSize();
1658 d->adjustComboBoxSize();
1660 }
1661}
1662
1673{
1674 Q_D(const QComboBox);
1675 if (d->iconSize.isValid())
1676 return d->iconSize;
1677
1678 int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
1679 return QSize(iconWidth, iconWidth);
1680}
1681
1683{
1684 Q_D(QComboBox);
1685 if (size == d->iconSize)
1686 return;
1687
1688 view()->setIconSize(size);
1689 d->iconSize = size;
1690 d->sizeHint = QSize();
1692}
1693
1710void QComboBox::setPlaceholderText(const QString &placeholderText)
1711{
1712 Q_D(QComboBox);
1713 if (placeholderText == d->placeholderText)
1714 return;
1715
1716 d->placeholderText = placeholderText;
1717 if (currentIndex() == -1) {
1718 if (d->placeholderText.isEmpty())
1719 setCurrentIndex(0);
1720 else
1721 update();
1722 } else {
1724 }
1725}
1726
1728{
1729 Q_D(const QComboBox);
1730 return d->placeholderText;
1731}
1732
1746{
1747 Q_D(const QComboBox);
1748 return d->lineEdit != nullptr;
1749}
1750
1759{
1760 Q_Q(QComboBox);
1762 q->initStyleOption(&opt);
1763 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
1764 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
1765 q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
1766 } else {
1767 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
1768 q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
1769 }
1770}
1771
1773{
1774 if (!index.isValid())
1775 return {};
1777 if (decoration.userType() == QMetaType::QPixmap)
1778 return QIcon(qvariant_cast<QPixmap>(decoration));
1779 else
1780 return qvariant_cast<QIcon>(decoration);
1781}
1782
1783void QComboBox::setEditable(bool editable)
1784{
1785 Q_D(QComboBox);
1786 if (isEditable() == editable)
1787 return;
1788
1791 if (editable) {
1792 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1793 d->viewContainer()->updateScrollers();
1794 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
1795 }
1796 QLineEdit *le = new QLineEdit(this);
1797 le->setPalette(palette());
1798 setLineEdit(le);
1799 } else {
1800 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1801 d->viewContainer()->updateScrollers();
1802 view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1803 }
1805 d->lineEdit->hide();
1806 d->lineEdit->deleteLater();
1807 d->lineEdit = nullptr;
1808 }
1809
1810 d->updateDelegate();
1811 d->updateFocusPolicy();
1812
1813 d->viewContainer()->updateTopBottomMargin();
1815 adjustSize();
1816}
1817
1827{
1828 Q_D(QComboBox);
1829 if (Q_UNLIKELY(!edit)) {
1830 qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
1831 return;
1832 }
1833
1834 if (edit == d->lineEdit)
1835 return;
1836
1838 delete d->lineEdit;
1839
1840 d->lineEdit = edit;
1841#ifndef QT_NO_IM
1842 qt_widget_private(d->lineEdit)->inheritsInputMethodHints = 1;
1843#endif
1844 if (d->lineEdit->parent() != this)
1845 d->lineEdit->setParent(this);
1856 QObjectPrivate::connect(d->lineEdit->d_func()->control, &QWidgetLineControl::updateMicroFocus,
1858 d->lineEdit->setFrame(false);
1859 d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
1860 d->updateFocusPolicy();
1861 d->lineEdit->setFocusProxy(this);
1862 d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
1863
1864#if QT_CONFIG(completer)
1865 // create a default completer
1866 if (!d->lineEdit->completer()) {
1867 QCompleter *completer = new QCompleter(d->model, d->lineEdit);
1870 completer->setCompletionColumn(d->modelColumn);
1871
1872#ifdef QT_KEYPAD_NAVIGATION
1873 // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
1874 // This means that when the user enters edit mode they are immediately presented with a
1875 // list of possible completions.
1876 if (QApplicationPrivate::keypadNavigationEnabled())
1878#endif
1879 // sets up connections
1881 }
1882#endif
1883
1885 d->updateLayoutDirection();
1886 d->updateLineEditGeometry();
1887 if (isVisible())
1888 d->lineEdit->show();
1889
1890 update();
1891}
1892
1900{
1901 Q_D(const QComboBox);
1902 return d->lineEdit;
1903}
1904
1905#ifndef QT_NO_VALIDATOR
1915{
1916 Q_D(QComboBox);
1917 if (d->lineEdit)
1918 d->lineEdit->setValidator(v);
1919}
1920
1928{
1929 Q_D(const QComboBox);
1930 return d->lineEdit ? d->lineEdit->validator() : nullptr;
1931}
1932#endif // QT_NO_VALIDATOR
1933
1934#if QT_CONFIG(completer)
1935
1950void QComboBox::setCompleter(QCompleter *c)
1951{
1952 Q_D(QComboBox);
1953 if (!d->lineEdit) {
1954 qWarning("Setting a QCompleter on non-editable QComboBox is not allowed.");
1955 return;
1956 }
1957 d->lineEdit->setCompleter(c);
1958 if (c) {
1960 d, &QComboBoxPrivate::completerActivated);
1961 c->setWidget(this);
1962 }
1963}
1964
1973QCompleter *QComboBox::completer() const
1974{
1975 Q_D(const QComboBox);
1976 return d->lineEdit ? d->lineEdit->completer() : nullptr;
1977}
1978
1979#endif // QT_CONFIG(completer)
1980
1990
2007{
2008 if (Q_UNLIKELY(!delegate)) {
2009 qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
2010 return;
2011 }
2012 view()->setItemDelegate(delegate);
2013}
2014
2020{
2021 Q_D(const QComboBox);
2023 QComboBox *that = const_cast<QComboBox*>(this);
2024 that->setModel(new QStandardItemModel(0, 1, that));
2025 }
2026 return d->model;
2027}
2028
2039{
2040 Q_D(QComboBox);
2041
2042 if (Q_UNLIKELY(!model)) {
2043 qWarning("QComboBox::setModel: cannot set a 0 model");
2044 return;
2045 }
2046
2047 if (model == d->model)
2048 return;
2049
2050#if QT_CONFIG(completer)
2051 if (d->lineEdit && d->lineEdit->completer())
2052 d->lineEdit->completer()->setModel(model);
2053#endif
2054 d->disconnectModel();
2055 if (d->model && d->model->QObject::parent() == this) {
2056 delete d->model;
2057 d->model = nullptr;
2058 }
2059
2060 d->model = model;
2061
2062 if (d->container) {
2063 d->container->itemView()->setModel(model);
2064 QObjectPrivate::connect(d->container->itemView()->selectionModel(),
2067 }
2068
2069 d->connectModel();
2070
2072
2073 d->trySetValidIndex();
2074 d->modelChanged();
2075}
2076
2101
2107
2115{
2116 Q_D(const QComboBox);
2117 return QModelIndex(d->root);
2118}
2119
2126{
2127 Q_D(QComboBox);
2128 if (d->root == index)
2129 return;
2130 d->root = QPersistentModelIndex(index);
2132 update();
2133}
2134
2145{
2146 Q_D(const QComboBox);
2147 return d->currentIndex.row();
2148}
2149
2151{
2152 Q_D(QComboBox);
2153 QModelIndex mi = index >= 0 ? d->model->index(index, d->modelColumn, d->root) : QModelIndex();
2154 d->setCurrentIndex(mi);
2155}
2156
2158{
2159 if (isEditable()) {
2161 } else {
2162 const int i = findText(text);
2163 if (i > -1)
2165 }
2166}
2167
2169{
2170 Q_Q(QComboBox);
2171
2172 QModelIndex normalized = mi.sibling(mi.row(), modelColumn); // no-op if mi.column() == modelColumn
2173 if (!normalized.isValid())
2174 normalized = mi; // Fallback to passed index.
2175
2176 bool indexChanged = (normalized != currentIndex);
2177 if (indexChanged)
2179 if (lineEdit) {
2180 const QString newText = itemText(normalized);
2181 if (lineEdit->text() != newText) {
2182 lineEdit->setText(newText); // may cause lineEdit -> nullptr (QTBUG-54191)
2183#if QT_CONFIG(completer)
2184 if (lineEdit && lineEdit->completer())
2185 lineEdit->completer()->setCompletionPrefix(newText);
2186#endif
2187 }
2189 }
2190 // If the model was reset to an empty one, currentIndex will be invalidated
2191 // (because it's a QPersistentModelIndex), but the index change will never
2192 // be advertised. So an explicit check for this condition is needed.
2193 // The variable used for that check has to be reset when a previously valid
2194 // index becomes invalid.
2195 const bool modelResetToEmpty = !normalized.isValid() && indexBeforeChange != -1;
2196 if (modelResetToEmpty)
2197 indexBeforeChange = -1;
2198
2199 if (indexChanged || modelResetToEmpty) {
2200 QItemSelectionModel::SelectionFlags selectionMode = QItemSelectionModel::ClearAndSelect;
2201 if (q->view()->selectionBehavior() == QAbstractItemView::SelectRows)
2202 selectionMode.setFlag(QItemSelectionModel::Rows);
2203 if (auto *model = q->view()->selectionModel())
2204 model->setCurrentIndex(currentIndex, selectionMode);
2205
2206 q->update();
2208 }
2209}
2210
2226{
2227 Q_D(const QComboBox);
2228 if (d->lineEdit)
2229 return d->lineEdit->text();
2230 if (d->currentIndex.isValid())
2231 return d->itemText(d->currentIndex);
2232 return {};
2233}
2234
2244{
2245 Q_D(const QComboBox);
2246 return d->currentIndex.data(role);
2247}
2248
2253{
2254 Q_D(const QComboBox);
2255 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2256 return d->itemText(mi);
2257}
2258
2263{
2264 Q_D(const QComboBox);
2265 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2266 return d->itemIcon(mi);
2267}
2268
2274{
2275 Q_D(const QComboBox);
2276 QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2277 return d->model->data(mi, role);
2278}
2279
2306void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)
2307{
2308 Q_D(QComboBox);
2309 int itemCount = count();
2310 index = qBound(0, index, itemCount);
2311 if (index >= d->maxCount)
2312 return;
2313
2314 // For the common case where we are using the built in QStandardItemModel
2315 // construct a QStandardItem, reducing the number of expensive signals from the model
2316 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2319 if (userData.isValid()) item->setData(userData, Qt::UserRole);
2320 m->insertRow(index, item);
2321 ++itemCount;
2322 } else {
2323 d->inserting = true;
2324 if (d->model->insertRows(index, 1, d->root)) {
2325 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2326 if (icon.isNull() && !userData.isValid()) {
2327 d->model->setData(item, text, Qt::EditRole);
2328 } else {
2329 QMap<int, QVariant> values;
2330 if (!text.isNull()) values.insert(Qt::EditRole, text);
2331 if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
2332 if (userData.isValid()) values.insert(Qt::UserRole, userData);
2333 if (!values.isEmpty()) d->model->setItemData(item, values);
2334 }
2335 d->inserting = false;
2336 d->rowsInserted(d->root, index, index);
2337 ++itemCount;
2338 } else {
2339 d->inserting = false;
2340 }
2341 }
2342
2343 if (itemCount > d->maxCount)
2344 d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
2345}
2346
2358{
2359 Q_D(QComboBox);
2360 if (list.isEmpty())
2361 return;
2362 index = qBound(0, index, count());
2363 int insertCount = qMin(d->maxCount - index, list.size());
2364 if (insertCount <= 0)
2365 return;
2366 // For the common case where we are using the built in QStandardItemModel
2367 // construct a QStandardItem, reducing the number of expensive signals from the model
2368 if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2369 QList<QStandardItem *> items;
2370 items.reserve(insertCount);
2371 QStandardItem *hiddenRoot = m->invisibleRootItem();
2372 for (int i = 0; i < insertCount; ++i)
2374 hiddenRoot->insertRows(index, items);
2375 } else {
2376 d->inserting = true;
2377 if (d->model->insertRows(index, insertCount, d->root)) {
2379 for (int i = 0; i < insertCount; ++i) {
2380 item = d->model->index(i+index, d->modelColumn, d->root);
2381 d->model->setData(item, list.at(i), Qt::EditRole);
2382 }
2383 d->inserting = false;
2384 d->rowsInserted(d->root, index, index + insertCount - 1);
2385 } else {
2386 d->inserting = false;
2387 }
2388 }
2389
2390 int mc = count();
2391 if (mc > d->maxCount)
2392 d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);
2393}
2394
2407{
2408 Q_D(QComboBox);
2409 int itemCount = count();
2410 index = qBound(0, index, itemCount);
2411 if (index >= d->maxCount)
2412 return;
2414 QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));
2415}
2416
2424{
2425 Q_D(QComboBox);
2426 if (index < 0 || index >= count())
2427 return;
2428 d->model->removeRows(index, 1, d->root);
2429}
2430
2435{
2436 Q_D(const QComboBox);
2437 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2438 if (item.isValid()) {
2439 d->model->setData(item, text, Qt::EditRole);
2440 }
2441}
2442
2447{
2448 Q_D(const QComboBox);
2449 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2450 if (item.isValid()) {
2452 }
2453}
2454
2459void QComboBox::setItemData(int index, const QVariant &value, int role)
2460{
2461 Q_D(const QComboBox);
2462 QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2463 if (item.isValid()) {
2464 d->model->setData(item, value, role);
2465 }
2466}
2467
2472{
2473 Q_D(const QComboBox);
2474 return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();
2475}
2476
2487{
2488 Q_D(QComboBox);
2489 if (Q_UNLIKELY(!itemView)) {
2490 qWarning("QComboBox::setView: cannot set a 0 view");
2491 return;
2492 }
2493
2494 if (itemView->model() != d->model) {
2495 d->disconnectModel();
2496 itemView->setModel(d->model);
2497 d->connectModel();
2498 }
2499 d->viewContainer()->setItemView(itemView);
2500}
2501
2506{
2507 Q_D(const QComboBox);
2508 return d->recomputeSizeHint(d->minimumSizeHint);
2509}
2510
2519{
2520 Q_D(const QComboBox);
2521 return d->recomputeSizeHint(d->sizeHint);
2522}
2523
2524#ifdef Q_OS_MAC
2525void QComboBoxPrivate::cleanupNativePopup()
2526{
2527 if (!m_platformMenu)
2528 return;
2529
2530 m_platformMenu->setVisible(false);
2531 int count = int(m_platformMenu->tag());
2532 for (int i = 0; i < count; ++i)
2533 m_platformMenu->menuItemAt(i)->deleteLater();
2534
2535 delete m_platformMenu;
2536 m_platformMenu = nullptr;
2537}
2538
2545bool QComboBoxPrivate::showNativePopup()
2546{
2547 Q_Q(QComboBox);
2548
2549 cleanupNativePopup();
2550
2551 QPlatformTheme *theme = QGuiApplicationPrivate::instance()->platformTheme();
2552 m_platformMenu = theme->createPlatformMenu();
2553 if (!m_platformMenu)
2554 return false;
2555
2556 int itemsCount = q->count();
2557 m_platformMenu->setTag(quintptr(itemsCount));
2558
2559 QPlatformMenuItem *currentItem = nullptr;
2560 int currentIndex = q->currentIndex();
2561
2562 for (int i = 0; i < itemsCount; ++i) {
2564 QModelIndex rowIndex = model->index(i, modelColumn, root);
2565 QVariant textVariant = model->data(rowIndex, Qt::EditRole);
2566 item->setText(textVariant.toString());
2567 QVariant iconVariant = model->data(rowIndex, Qt::DecorationRole);
2568 const Qt::ItemFlags itemFlags = model->flags(rowIndex);
2569 if (iconVariant.canConvert<QIcon>())
2570 item->setIcon(iconVariant.value<QIcon>());
2571 item->setCheckable(true);
2572 item->setChecked(i == currentIndex);
2573 item->setEnabled(itemFlags & Qt::ItemIsEnabled);
2574 if (!currentItem || i == currentIndex)
2575 currentItem = item;
2576
2577 IndexSetter setter = { i, q };
2579
2580 m_platformMenu->insertMenuItem(item, 0);
2581 m_platformMenu->syncMenuItem(item);
2582 }
2583
2584 QWindow *tlw = q->window()->windowHandle();
2585 m_platformMenu->setFont(q->font());
2586 m_platformMenu->setMinimumWidth(q->rect().width());
2587 QPoint offset = QPoint(0, 7);
2588 if (q->testAttribute(Qt::WA_MacSmallSize))
2589 offset = QPoint(-1, 7);
2590 else if (q->testAttribute(Qt::WA_MacMiniSize))
2591 offset = QPoint(-2, 6);
2592
2593 [[maybe_unused]] QPointer<QComboBox> guard(q);
2594 const QRect targetRect = QRect(tlw->mapFromGlobal(q->mapToGlobal(offset)), QSize());
2595 m_platformMenu->showPopup(tlw, QHighDpi::toNativePixels(targetRect, tlw), currentItem);
2596
2597#ifdef Q_OS_MACOS
2598 if (guard) {
2599 // The Cocoa popup will swallow any mouse release event.
2600 // We need to fake one here to un-press the button.
2601 QMouseEvent mouseReleased(QEvent::MouseButtonRelease, q->pos(), q->mapToGlobal(QPoint(0, 0)),
2602 Qt::LeftButton, Qt::MouseButtons(Qt::LeftButton), {});
2603 QCoreApplication::sendEvent(q, &mouseReleased);
2604 }
2605#endif
2606
2607 return true;
2608}
2609
2610#endif // Q_OS_MAC
2611
2622{
2623 Q_D(QComboBox);
2624 if (count() <= 0)
2625 return;
2626
2627 QStyle * const style = this->style();
2630 const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
2631
2632#ifdef Q_OS_MAC
2633 if (usePopup
2634 && (!d->container
2635 || (view()->metaObject()->className() == QByteArray("QComboBoxListView")
2636 && view()->itemDelegate()->metaObject()->className() == QByteArray("QComboMenuDelegate")))
2638 && d->showNativePopup())
2639 return;
2640#endif // Q_OS_MAC
2641
2642 QComboBoxPrivateContainer* container = d->viewContainer();
2645 QRect screen = d->popupGeometry(mapToGlobal(listRect.topLeft()));
2646
2647 QPoint below = mapToGlobal(listRect.bottomLeft());
2648 int belowHeight = screen.bottom() - below.y();
2649 QPoint above = mapToGlobal(listRect.topLeft());
2650 int aboveHeight = above.y() - screen.y();
2651 bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);
2652 const auto listView = qobject_cast<QListView *>(d->viewContainer()->itemView());
2653
2654 {
2655 int listHeight = 0;
2656 int count = 0;
2657 QStack<QModelIndex> toCheck;
2658 toCheck.push(view()->rootIndex());
2659#if QT_CONFIG(treeview)
2660 QTreeView *treeView = qobject_cast<QTreeView*>(view());
2661 if (treeView && treeView->header() && !treeView->header()->isHidden())
2662 listHeight += treeView->header()->height();
2663#endif
2664 while (!toCheck.isEmpty()) {
2665 QModelIndex parent = toCheck.pop();
2666 for (int i = 0, end = d->model->rowCount(parent); i < end; ++i) {
2667 if (listView && listView->isRowHidden(i))
2668 continue;
2669 QModelIndex idx = d->model->index(i, d->modelColumn, parent);
2670 if (!idx.isValid())
2671 continue;
2672 listHeight += view()->visualRect(idx).height();
2673#if QT_CONFIG(treeview)
2674 if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
2675 toCheck.push(idx);
2676#endif
2677 ++count;
2678 if (!usePopup && count >= d->maxVisibleItems) {
2679 toCheck.clear();
2680 break;
2681 }
2682 }
2683 }
2684 if (count > 1)
2685 listHeight += (count - 1) * container->spacing();
2686 listRect.setHeight(listHeight);
2687 }
2688
2689 {
2690 // add the spacing for the grid on the top and the bottom;
2691 int heightMargin = container->topMargin() + container->bottomMargin();
2692
2693 // add the frame of the container
2694 const QMargins cm = container->contentsMargins();
2695 heightMargin += cm.top() + cm.bottom();
2696
2697 //add the frame of the view
2698 const QMargins vm = view()->contentsMargins();
2699 heightMargin += vm.top() + vm.bottom();
2700 heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
2701 heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
2702
2703 listRect.setHeight(listRect.height() + heightMargin);
2704 }
2705
2706 // Add space for margin at top and bottom if the style wants it.
2707 if (usePopup)
2708 listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
2709
2710 // Make sure the popup is wide enough to display its contents.
2711 if (usePopup) {
2712 const int diff = d->computeWidthHint() - width();
2713 if (diff > 0)
2714 listRect.setWidth(listRect.width() + diff);
2715 }
2716
2717 //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
2718 container->layout()->activate();
2719 //takes account of the minimum/maximum size of the container
2720 listRect.setSize( listRect.size().expandedTo(container->minimumSize())
2721 .boundedTo(container->maximumSize()));
2722
2723 // make sure the widget fits on screen
2724 if (boundToScreen) {
2725 if (listRect.width() > screen.width() )
2726 listRect.setWidth(screen.width());
2727 if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
2728 below.setX(screen.x() + screen.width() - listRect.width());
2729 above.setX(screen.x() + screen.width() - listRect.width());
2730 }
2731 if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
2732 below.setX(screen.x());
2733 above.setX(screen.x());
2734 }
2735 }
2736
2737 if (usePopup) {
2738 // Position horizontally.
2739 listRect.moveLeft(above.x());
2740
2741 // Position vertically so the currently selected item lines up
2742 // with the combo box. In order to do that, make sure that the item
2743 // view is scrolled to the top first, otherwise calls to view()->visualRect()
2744 // will return the geometry the selected item had the last time the popup
2745 // was visible (and perhaps scrolled). And this will not match the geometry
2746 // it will actually have when we resize the container to fit all the items
2747 // further down in this function.
2748 view()->scrollToTop();
2749 const QRect currentItemRect = view()->visualRect(view()->currentIndex());
2750 const int offset = listRect.top() - currentItemRect.top();
2751 listRect.moveTop(above.y() + offset - listRect.top());
2752
2753 // Clamp the listRect height and vertical position so we don't expand outside the
2754 // available screen geometry.This may override the vertical position, but it is more
2755 // important to show as much as possible of the popup.
2756 const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
2757 listRect.setHeight(height);
2758
2759 if (boundToScreen) {
2760 if (listRect.top() < screen.top())
2761 listRect.moveTop(screen.top());
2762 if (listRect.bottom() > screen.bottom())
2763 listRect.moveBottom(screen.bottom());
2764 }
2765 } else if (!boundToScreen || listRect.height() <= belowHeight) {
2766 listRect.moveTopLeft(below);
2767 } else if (listRect.height() <= aboveHeight) {
2768 listRect.moveBottomLeft(above);
2769 } else if (belowHeight >= aboveHeight) {
2770 listRect.setHeight(belowHeight);
2771 listRect.moveTopLeft(below);
2772 } else {
2773 listRect.setHeight(aboveHeight);
2774 listRect.moveBottomLeft(above);
2775 }
2776
2777 if (qApp) {
2779 }
2780
2781 const QScrollBar *sb = view()->horizontalScrollBar();
2782 const auto needHorizontalScrollBar = [this, sb]{
2783 const Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();
2785 && sb->minimum() < sb->maximum();
2786 };
2787 const bool neededHorizontalScrollBar = needHorizontalScrollBar();
2788 if (neededHorizontalScrollBar)
2789 listRect.adjust(0, 0, 0, sb->height());
2790
2791 // Hide the scrollers here, so that the listrect gets the full height of the container
2792 // If the scrollers are truly needed, the later call to container->updateScrollers()
2793 // will make them visible again.
2794 container->hideScrollers();
2795 container->setGeometry(listRect);
2796
2797#ifndef Q_OS_MAC
2798 const bool updatesEnabled = container->updatesEnabled();
2799#endif
2800
2801#if QT_CONFIG(effects)
2802 bool scrollDown = (listRect.topLeft() == below);
2805 qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
2806#endif
2807
2808// Don't disable updates on OS X. Windows are displayed immediately on this platform,
2809// which means that the window will be visible before the call to container->show() returns.
2810// If updates are disabled at this point we'll miss our chance at painting the popup
2811// menu before it's shown, causing flicker since the window then displays the standard gray
2812// background.
2813#ifndef Q_OS_MAC
2814 container->setUpdatesEnabled(false);
2815#endif
2816
2817 bool startTimer = !container->isVisible();
2818 container->raise();
2819 container->create();
2820 if (QWindow *containerWindow = qt_widget_private(container)->windowHandle(QWidgetPrivate::WindowHandleMode::TopLevel)) {
2821 QScreen *currentScreen = d->associatedScreen();
2822 if (currentScreen && !currentScreen->virtualSiblings().contains(containerWindow->screen())) {
2823 containerWindow->setScreen(currentScreen);
2824
2825 // This seems to workaround an issue in xcb+multi GPU+multiscreen
2826 // environment where the window might not always show up when screen
2827 // is changed.
2828 container->hide();
2829 }
2830 }
2831 container->show();
2832 if (!neededHorizontalScrollBar && needHorizontalScrollBar()) {
2833 listRect.adjust(0, 0, 0, sb->height());
2834 container->setGeometry(listRect);
2835 }
2836
2837 container->updateScrollers();
2838 view()->setFocus();
2839
2844
2845#ifndef Q_OS_MAC
2847#endif
2848
2849 container->update();
2850 if (startTimer) {
2851 container->popupTimer.start();
2852 container->maybeIgnoreMouseButtonRelease = true;
2853 }
2854}
2855
2867{
2868 Q_D(QComboBox);
2869 if (d->hidingPopup)
2870 return;
2871 d->hidingPopup = true;
2872 // can't use QBoolBlocker on a bitfield
2873 auto resetHidingPopup = qScopeGuard([d]{
2874 d->hidingPopup = false;
2875 });
2876
2877 if (!d->container || !d->container->isVisible())
2878 return;
2879
2880#if QT_CONFIG(effects)
2881 QItemSelectionModel *selectionModel = d->container->itemView()
2882 ? d->container->itemView()->selectionModel() : nullptr;
2883 // Flash selected/triggered item (if any) before hiding the popup.
2884 if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem) &&
2885 selectionModel && selectionModel->hasSelection()) {
2886 const QItemSelection selection = selectionModel->selection();
2887
2888 QTimer::singleShot(0, d->container, [d, selection, selectionModel]{
2889 QSignalBlocker modelBlocker(d->model);
2890 QSignalBlocker viewBlocker(d->container->itemView());
2891 QSignalBlocker containerBlocker(d->container);
2892
2893 // Deselect item and wait 60 ms.
2894 selectionModel->select(selection, QItemSelectionModel::Toggle);
2895 QTimer::singleShot(60, d->container, [d, selection, selectionModel]{
2896 QSignalBlocker modelBlocker(d->model);
2897 QSignalBlocker viewBlocker(d->container->itemView());
2898 QSignalBlocker containerBlocker(d->container);
2899 selectionModel->select(selection, QItemSelectionModel::Toggle);
2900 QTimer::singleShot(20, d->container, [d] {
2901 d->doHidePopup();
2902 });
2903 });
2904 });
2905 } else
2906#endif // QT_CONFIG(effects)
2907 {
2908 d->doHidePopup();
2909 }
2910}
2911
2913{
2914 if (container && container->isVisible())
2915 container->hide();
2916
2917 resetButton();
2918}
2919
2921{
2922 if (text == currentText)
2923 return;
2924
2925 currentText = text;
2926 emit q_func()->currentTextChanged(text);
2927}
2928
2936{
2937 Q_D(QComboBox);
2938 d->model->removeRows(0, d->model->rowCount(d->root), d->root);
2939#if QT_CONFIG(accessibility)
2940 QAccessibleValueChangeEvent event(this, QString());
2941 QAccessible::updateAccessibility(&event);
2942#endif
2943}
2944
2949{
2950 Q_D(QComboBox);
2951 if (d->lineEdit)
2952 d->lineEdit->clear();
2953#if QT_CONFIG(accessibility)
2954 QAccessibleValueChangeEvent event(this, QString());
2955 QAccessible::updateAccessibility(&event);
2956#endif
2957}
2958
2963{
2964 Q_D(QComboBox);
2965 if (d->lineEdit)
2966 d->lineEdit->setText(text);
2967#if QT_CONFIG(accessibility)
2968 QAccessibleValueChangeEvent event(this, text);
2969 QAccessible::updateAccessibility(&event);
2970#endif
2971}
2972
2977{
2978 Q_D(QComboBox);
2979 update();
2980 if (d->lineEdit) {
2981 d->lineEdit->event(e);
2982#if QT_CONFIG(completer)
2983 if (d->lineEdit->completer())
2984 d->lineEdit->completer()->setWidget(this);
2985#endif
2986 }
2987}
2988
2993{
2994 Q_D(QComboBox);
2995 update();
2996 if (d->lineEdit)
2997 d->lineEdit->event(e);
2998}
2999
3002{
3003 Q_D(QComboBox);
3004 switch (e->type()) {
3006 if (d->container)
3007 d->container->updateStyleSettings();
3008 d->updateDelegate();
3009
3010#ifdef Q_OS_MAC
3012#endif
3013 d->sizeHint = QSize(); // invalidate size hint
3014 d->minimumSizeHint = QSize();
3015 d->updateLayoutDirection();
3016 if (d->lineEdit)
3017 d->updateLineEditGeometry();
3018 d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
3019
3020 if (e->type() == QEvent::MacSizeChange) {
3027 QFont f = font();
3028 f.setPointSizeF(platformFont->pointSizeF());
3029 setFont(f);
3030 }
3031 }
3032 // ### need to update scrollers etc. as well here
3033 break;
3035 if (!isEnabled())
3036 hidePopup();
3037 break;
3038 case QEvent::PaletteChange: {
3039 d->updateViewContainerPaletteAndOpacity();
3040 break;
3041 }
3042 case QEvent::FontChange: {
3043 d->sizeHint = QSize(); // invalidate size hint
3044 d->viewContainer()->setFont(font());
3045 d->viewContainer()->itemView()->doItemsLayout();
3046 if (d->lineEdit)
3047 d->updateLineEditGeometry();
3048 break;
3049 }
3050 default:
3051 break;
3052 }
3054}
3055
3060{
3061 Q_D(QComboBox);
3062 d->updateLineEditGeometry();
3063}
3064
3069{
3070 QStylePainter painter(this);
3072
3073 // draw the combobox frame, focusrect and selected etc.
3076 painter.drawComplexControl(QStyle::CC_ComboBox, opt);
3077
3078 if (currentIndex() < 0 && !placeholderText().isEmpty()) {
3080 opt.currentText = placeholderText();
3081 }
3082
3083 // draw the icon and text
3084 painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
3085}
3086
3091{
3092 Q_D(QComboBox);
3093 if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
3094 d->sizeHint = QSize();
3096 }
3097 d->shownOnce = true;
3099}
3100
3105{
3106 hidePopup();
3107}
3108
3113{
3114 Q_D(QComboBox);
3115 switch(event->type()) {
3118 d->updateLayoutDirection();
3119 d->updateLineEditGeometry();
3120 break;
3121 case QEvent::HoverEnter:
3122 case QEvent::HoverLeave:
3123 case QEvent::HoverMove:
3124 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
3125 d->updateHoverControl(he->position().toPoint());
3126 break;
3128 if (d->lineEdit)
3129 return d->lineEdit->event(event);
3130 break;
3131#ifdef QT_KEYPAD_NAVIGATION
3132 case QEvent::EnterEditFocus:
3133 if (d->lineEdit)
3134 d->lineEdit->event(event); //so cursor starts
3135 break;
3136 case QEvent::LeaveEditFocus:
3137 if (d->lineEdit)
3138 d->lineEdit->event(event); //so cursor stops
3139 break;
3140#endif
3141 default:
3142 break;
3143 }
3144 return QWidget::event(event);
3145}
3146
3151{
3152 Q_D(QComboBox);
3153 if (!QGuiApplication::styleHints()->setFocusOnTouchRelease())
3154 d->showPopupFromMouseEvent(e);
3155}
3156
3158{
3159 Q_Q(QComboBox);
3161 q->initStyleOption(&opt);
3162 QStyle::SubControl sc = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->position().toPoint(), q);
3163
3164 if (e->button() == Qt::LeftButton
3165 && !(sc == QStyle::SC_None && e->type() == QEvent::MouseButtonRelease)
3166 && (sc == QStyle::SC_ComboBoxArrow || !q->isEditable())
3167 && !viewContainer()->isVisible()) {
3168 if (sc == QStyle::SC_ComboBoxArrow)
3170#ifdef QT_KEYPAD_NAVIGATION
3171 //if the container already exists, then d->viewContainer() is safe to call
3172 if (container) {
3173#else
3174 if (true) {
3175#endif
3176 // We've restricted the next couple of lines, because by not calling
3177 // viewContainer(), we avoid creating the QComboBoxPrivateContainer.
3178 viewContainer()->initialClickPosition = q->mapToGlobal(e->position().toPoint());
3179 }
3180 QPointer<QComboBox> guard = q;
3181 q->showPopup();
3182 if (!guard)
3183 return;
3184 // The code below ensures that regular mousepress and pick item still works
3185 // If it was not called the viewContainer would ignore event since it didn't have
3186 // a mousePressEvent first.
3187 if (viewContainer()) {
3189 viewContainer()->maybeIgnoreMouseButtonRelease = false;
3190 }
3191 } else {
3192#ifdef QT_KEYPAD_NAVIGATION
3193 if (QApplicationPrivate::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) {
3194 lineEdit->event(e); //so lineedit can move cursor, etc
3195 return;
3196 }
3197#endif
3198 e->ignore();
3199 }
3200}
3201
3206{
3207 Q_D(QComboBox);
3208 d->updateArrow(QStyle::State_None);
3209 if (QGuiApplication::styleHints()->setFocusOnTouchRelease() && hasFocus())
3210 d->showPopupFromMouseEvent(e);
3211}
3212
3217{
3218 Q_D(QComboBox);
3219
3220#if QT_CONFIG(completer)
3221 if (const auto *cmpltr = completer()) {
3222 const auto *popup = QCompleterPrivate::get(cmpltr)->popup;
3223 if (popup && popup->isVisible()) {
3224 // provide same autocompletion support as line edit
3225 d->lineEdit->event(e);
3226 return;
3227 }
3228 }
3229#endif
3230
3231 enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};
3232
3233 Move move = NoMove;
3234 int newIndex = currentIndex();
3235
3236 bool pressLikeButton = !d->lineEdit;
3237#ifdef QT_KEYPAD_NAVIGATION
3238 pressLikeButton |= QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus();
3239#endif
3240 auto key = e->key();
3241 if (pressLikeButton) {
3242 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()
3244 .value<QList<Qt::Key>>();
3245 if (buttonPressKeys.contains(key)) {
3246 showPopup();
3247 return;
3248 }
3249 }
3250
3251 switch (key) {
3252 case Qt::Key_Up:
3253 if (e->modifiers() & Qt::ControlModifier)
3254 break; // pass to line edit for auto completion
3255 Q_FALLTHROUGH();
3256 case Qt::Key_PageUp:
3257#ifdef QT_KEYPAD_NAVIGATION
3258 if (QApplicationPrivate::keypadNavigationEnabled())
3259 e->ignore();
3260 else
3261#endif
3262 move = MoveUp;
3263 break;
3264 case Qt::Key_Down:
3265 if (e->modifiers() & Qt::AltModifier) {
3266 showPopup();
3267 return;
3268 } else if (e->modifiers() & Qt::ControlModifier)
3269 break; // pass to line edit for auto completion
3270 Q_FALLTHROUGH();
3271 case Qt::Key_PageDown:
3272#ifdef QT_KEYPAD_NAVIGATION
3273 if (QApplicationPrivate::keypadNavigationEnabled())
3274 e->ignore();
3275 else
3276#endif
3277 move = MoveDown;
3278 break;
3279 case Qt::Key_Home:
3280 if (!d->lineEdit)
3281 move = MoveFirst;
3282 break;
3283 case Qt::Key_End:
3284 if (!d->lineEdit)
3285 move = MoveLast;
3286 break;
3287 case Qt::Key_F4:
3288 if (!e->modifiers()) {
3289 showPopup();
3290 return;
3291 }
3292 break;
3293 case Qt::Key_Enter:
3294 case Qt::Key_Return:
3295 case Qt::Key_Escape:
3296 if (!d->lineEdit)
3297 e->ignore();
3298 break;
3299#ifdef QT_KEYPAD_NAVIGATION
3300 case Qt::Key_Left:
3301 case Qt::Key_Right:
3302 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus())
3303 e->ignore();
3304 break;
3305 case Qt::Key_Back:
3306 if (QApplicationPrivate::keypadNavigationEnabled()) {
3307 if (!hasEditFocus() || !d->lineEdit)
3308 e->ignore();
3309 } else {
3310 e->ignore(); // let the surrounding dialog have it
3311 }
3312 break;
3313#endif
3314 default:
3315#if QT_CONFIG(shortcut)
3316 if (d->container && d->container->isVisible() && e->matches(QKeySequence::Cancel)) {
3317 hidePopup();
3318 e->accept();
3319 }
3320#endif
3321
3322 if (!d->lineEdit) {
3323 const auto text = e->text();
3324 if (!text.isEmpty() && text.at(0).isPrint())
3325 d->keyboardSearchString(text);
3326 else
3327 e->ignore();
3328 }
3329 }
3330
3331 const int rowCount = count();
3332
3333 if (move != NoMove) {
3334 e->accept();
3335 switch (move) {
3336 case MoveFirst:
3337 newIndex = -1;
3338 Q_FALLTHROUGH();
3339 case MoveDown:
3340 newIndex++;
3341 while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
3342 newIndex++;
3343 break;
3344 case MoveLast:
3345 newIndex = rowCount;
3346 Q_FALLTHROUGH();
3347 case MoveUp:
3348 newIndex--;
3349 while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3350 newIndex--;
3351 break;
3352 default:
3353 e->ignore();
3354 break;
3355 }
3356
3357 if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
3358 setCurrentIndex(newIndex);
3359 d->emitActivated(d->currentIndex);
3360 }
3361 } else if (d->lineEdit) {
3362 d->lineEdit->event(e);
3363 }
3364}
3365
3366
3371{
3372 Q_D(QComboBox);
3373 if (d->lineEdit)
3374 d->lineEdit->event(e);
3375 else
3377}
3378
3382#if QT_CONFIG(wheelevent)
3383void QComboBox::wheelEvent(QWheelEvent *e)
3384{
3385 Q_D(QComboBox);
3387 initStyleOption(&opt);
3388 if (style()->styleHint(QStyle::SH_ComboBox_AllowWheelScrolling, &opt, this) &&
3389 !d->viewContainer()->isVisible()) {
3390 const int rowCount = count();
3391 int newIndex = currentIndex();
3392 int delta = e->angleDelta().y();
3393
3394 if (delta > 0) {
3395 newIndex--;
3396 while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3397 newIndex--;
3398 } else if (delta < 0) {
3399 newIndex++;
3400 while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
3401 newIndex++;
3402 }
3403
3404 if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
3405 setCurrentIndex(newIndex);
3406 d->emitActivated(d->currentIndex);
3407 }
3408 e->accept();
3409 }
3410}
3411#endif
3412
3413#ifndef QT_NO_CONTEXTMENU
3418{
3419 Q_D(QComboBox);
3420 if (d->lineEdit) {
3421 Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();
3422 d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
3423 d->lineEdit->event(e);
3424 d->lineEdit->setContextMenuPolicy(p);
3425 }
3426}
3427#endif // QT_NO_CONTEXTMENU
3428
3430{
3431 // use keyboardSearch from the listView so we do not duplicate code
3433 view->setCurrentIndex(currentIndex);
3434 int currentRow = view->currentIndex().row();
3435 view->keyboardSearch(text);
3436 if (currentRow != view->currentIndex().row()) {
3437 setCurrentIndex(view->currentIndex());
3439 }
3440}
3441
3443{
3444 Q_Q(QComboBox);
3445
3447 sizeHint = QSize();
3449 q->updateGeometry();
3450 }
3451}
3452
3457{
3458 Q_D(QComboBox);
3459 if (d->lineEdit) {
3460 d->lineEdit->event(e);
3461 } else {
3462 if (!e->commitString().isEmpty())
3463 d->keyboardSearchString(e->commitString());
3464 else
3465 e->ignore();
3466 }
3467}
3468
3473{
3474 Q_D(const QComboBox);
3475 if (d->lineEdit)
3476 return d->lineEdit->inputMethodQuery(query);
3478}
3479
3483{
3484 Q_D(const QComboBox);
3485 if (d->lineEdit)
3486 return d->lineEdit->inputMethodQuery(query, argument);
3488}
3489
3530{
3531 Q_D(const QComboBox);
3532 return d->frame;
3533}
3534
3535
3537{
3538 Q_D(QComboBox);
3539 d->frame = enable;
3540 update();
3541 updateGeometry();
3542}
3543
3558{
3559 Q_D(const QComboBox);
3560 return d->modelColumn;
3561}
3562
3563void QComboBox::setModelColumn(int visibleColumn)
3564{
3565 Q_D(QComboBox);
3566 d->modelColumn = visibleColumn;
3567 QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());
3568 if (lv)
3569 lv->setModelColumn(visibleColumn);
3570#if QT_CONFIG(completer)
3571 if (d->lineEdit && d->lineEdit->completer())
3572 d->lineEdit->completer()->setCompletionColumn(visibleColumn);
3573#endif
3574 setCurrentIndex(currentIndex()); //update the text to the text of the new column;
3575}
3576
3578
3579#include "moc_qcombobox.cpp"
3580#include "moc_qcombobox_p.cpp"
The QAbstractItemDelegate class is used to display and edit data items from a model.
static QAbstractItemModel * staticEmptyModel()
void modelAboutToBeReset(QPrivateSignal)
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are inserted into the model.
virtual Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
void modelReset(QPrivateSignal)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
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.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are removed from the model.
void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been inserted into the model.
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.
void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been removed from the model.
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,...
void valueChanged(int value)
This signal is emitted when the slider value has changed, with the new slider value as argument.
SliderAction
\value SliderNoAction \value SliderSingleStepAdd \value SliderSingleStepSub \value SliderPageStepAdd ...
void rangeChanged(int min, int max)
This signal is emitted when the slider range has changed, with min being the new minimum,...
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
\inmodule QtGui
Definition qbrush.h:30
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 doScroll(int action)
QPointer< QComboBoxPrivateContainer > container
void rowsRemoved(const QModelIndex &parent, int start, int end)
void emitActivated(const QModelIndex &index)
QComboBox::InsertPolicy insertPolicy
QComboBoxPrivateContainer * viewContainer()
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void emitHighlighted(const QModelIndex &index)
QStyle::SubControl hoverControl
void keyboardSearchString(const QString &text)
void updateViewContainerPaletteAndOpacity()
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
void emitCurrentIndexChanged(const QModelIndex &index)
int itemRole() const
std::array< QMetaObject::Connection, 8 > modelConnections
QString placeholderText
int computeWidthHint() const
void rowsInserted(const QModelIndex &parent, int start, int end)
void setCurrentIndex(const QModelIndex &index)
QRect popupGeometry(const QPoint &globalPos) const
void updateArrow(QStyle::StateFlag state)
QAbstractItemModel * model
QComboBox::SizeAdjustPolicy sizeAdjustPolicy
QString itemText(const QModelIndex &index) const
void updateDelegate(bool force=false)
void adjustComboBoxSize()
QStyle::StateFlag arrowState
bool updateHoverControl(const QPoint &pos)
void updateCurrentText(const QString &text)
void updateMicroFocus()
void itemSelected(const QModelIndex &item)
void updateLineEditGeometry()
void updateIndexBeforeChange()
void updateLayoutDirection()
void trySetValidIndex()
The QComboBox widget combines a button with a dropdown 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:215
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
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,...
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)
void activated(const QString &text)
This signal is sent when an item in the popup() is activated by the user (by clicking or pressing ret...
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
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
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
\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
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
qreal height() const
Returns the height of the font.
\reentrant \inmodule QtGui
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:22
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:1054
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
\inmodule QtGui
Definition qevent.h:246
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:1019
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget.
Definition qevent.h:652
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current item changes.
\inmodule QtCore
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
QString text() const
Returns the Unicode text that this key generated.
Definition qevent.h:443
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
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:995
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
void selectionChanged()
This signal is emitted whenever the selection changes.
bool event(QEvent *) override
\reimp
void returnPressed()
This signal is emitted when the Return or Enter key is used.
void cursorPositionChanged(int, int)
This signal is emitted whenever the cursor moves.
void selectAll()
Selects all the text (highlights it) and moves the cursor to the end.
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
void textChanged(const QString &)
This signal is emitted whenever the text changes.
void setText(const QString &)
void editingFinished()
This signal is emitted when the Return or Enter key is used, or if the line edit loses focus and its ...
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
bool isRowHidden(int row) const
Returns true if the row is hidden; otherwise returns false.
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
T & first()
Definition qlist.h:645
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void reserve(qsizetype size)
Definition qlist.h:753
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
Definition qmargins.h:24
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
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:196
QObject * parent
Definition qobject.h:73
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
\inmodule QtCore
Definition qobject.h:103
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:1817
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
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:1555
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
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:486
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 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:151
@ Disabled
Definition qpalette.h:49
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
Definition qpalette.cpp:963
const QBrush & placeholderText() const
Definition qpalette.h:102
@ ButtonText
Definition qpalette.h:52
@ WindowText
Definition qpalette.h:51
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
The QPlatformTheme class allows customizing the UI based on themes.
virtual QPlatformMenuItem * createPlatformMenuItem() const
virtual QPlatformMenu * createPlatformMenu() const
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:140
\inmodule QtCore\reentrant
Definition qrect.h:30
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
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:578
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:123
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:136
constexpr int & rwidth() noexcept
Returns a reference to the width.
Definition qsize.h:154
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
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:127
The QSpacerItem class provides blank space in a layout.
Definition qlayoutitem.h:57
QSpacerItem * spacerItem() override
Returns a pointer to this object.
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...
The QStandardItemModel class provides a generic model for storing custom data.
The QStandardItem class provides an item for use with the QStandardItemModel class.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
QString toLower() const &
Definition qstring.h:435
The QStyleHintReturnMask class provides style hints that return a QRegion.
\variable QStyleOptionToolButton::features
\variable QStyleOptionProgressBar::minimum
The QStyleOption class stores the parameters used by QStyle functions.
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:2420
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:551
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:604
@ SH_Menu_Mask
Definition qstyle.h:665
@ SH_ComboBox_Popup
Definition qstyle.h:610
@ SH_ComboBox_UseNativePopup
Definition qstyle.h:689
@ SH_Menu_FlashTriggeredItem
Definition qstyle.h:666
@ SH_ComboBox_PopupFrameStyle
Definition qstyle.h:654
@ SH_ComboBox_LayoutDirection
Definition qstyle.h:643
@ SH_ComboBox_AllowWheelScrolling
Definition qstyle.h:701
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:2173
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:495
@ 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
\inmodule QtCore
Definition qcoreevent.h:366
void setSingleShot(bool singleShot)
Definition qtimer.cpp:552
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition qtimer.cpp:241
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition qtimer.cpp:167
bool singleShot
whether the timer is a single-shot timer
Definition qtimer.h:22
void stop()
Stops the timer.
Definition qtimer.cpp:267
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:65
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:714
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:339
void setLayoutItemMargins(int left, int top, int right, int bottom)
static QRect screenGeometry(const QWidget *widget)
Definition qwidget_p.h:469
void update(T t)
static QRect availableScreenGeometry(const QWidget *widget)
Definition qwidget_p.h:474
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:4313
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:7858
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:4530
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:8743
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:9641
void hide()
Hides the widget.
Definition qwidget.cpp:8135
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9913
void setLayoutDirection(Qt::LayoutDirection direction)
Definition qwidget.cpp:4879
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
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:9382
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
void setFont(const QFont &)
Definition qwidget.cpp:4667
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:1156
bool hasFocus() const
Definition qwidget.cpp:6446
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:9822
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:8822
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2496
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:7654
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:1705
#define this
Definition dialogs.cpp:9
QOpenGLWidget * widget
[1]
QString text
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)
Definition qcompare.h:63
CheckState
@ Unchecked
@ Checked
InputMethodQuery
@ AlignRight
Definition qnamespace.h:146
@ LeftButton
Definition qnamespace.h:58
@ WA_MacMiniSize
Definition qnamespace.h:363
@ WA_WindowPropagation
Definition qnamespace.h:349
@ WA_Resized
Definition qnamespace.h:308
@ WA_Hover
Definition qnamespace.h:340
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_X11NetWmWindowTypeCombo
Definition qnamespace.h:397
@ WA_NoMouseReplay
Definition qnamespace.h:320
@ WA_MacShowFocusRect
Definition qnamespace.h:359
@ WA_SetFont
Definition qnamespace.h:304
@ WA_MacSmallSize
Definition qnamespace.h:362
@ WA_InputMethodEnabled
Definition qnamespace.h:295
LayoutDirection
@ WheelFocus
Definition qnamespace.h:111
@ TabFocus
Definition qnamespace.h:108
@ FontRole
@ TextAlignmentRole
@ ForegroundRole
@ UserRole
@ DecorationRole
@ BackgroundRole
@ EditRole
@ CheckStateRole
@ DisplayRole
@ UI_AnimateCombo
@ Key_Escape
Definition qnamespace.h:663
@ Key_Select
@ Key_Return
Definition qnamespace.h:667
@ Key_Right
Definition qnamespace.h:679
@ Key_Enter
Definition qnamespace.h:668
@ Key_PageUp
Definition qnamespace.h:681
@ Key_Space
Definition qnamespace.h:513
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ Key_F4
Definition qnamespace.h:693
@ Key_PageDown
Definition qnamespace.h:682
@ Key_Back
Definition qnamespace.h:846
@ Key_Home
Definition qnamespace.h:675
@ Key_End
Definition qnamespace.h:676
ScrollBarPolicy
@ ScrollBarAlwaysOff
@ ScrollBarAlwaysOn
@ ScrollBarAsNeeded
@ ControlModifier
@ AltModifier
@ CaseInsensitive
@ CaseSensitive
@ UniqueConnection
ContextMenuPolicy
@ DefaultContextMenu
@ NoContextMenu
@ ElideMiddle
Definition qnamespace.h:191
@ ItemIsUserCheckable
@ ItemIsSelectable
@ ItemIsEnabled
@ MatchCaseSensitive
@ MatchFixedString
FontHash * qt_app_fonts_hash()
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define qApp
DBusConnection * connection
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
Definition qeffects.cpp:525
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_CATCH(A)
#define QT_TRY
#define qWarning
Definition qlogging.h:166
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
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLint GLsizei width
GLuint color
[2]
GLint GLint bottom
GLbitfield flags
GLboolean enable
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:167
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()
QListView * listView
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