Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickcombobox.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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 "qquickcombobox_p.h"
5#include "qquickcontrol_p_p.h"
8#include "qquickpopup_p_p.h"
10
11#include <QtCore/qregularexpression.h>
12#include <QtCore/qabstractitemmodel.h>
13#include <QtCore/qglobal.h>
14#include <QtGui/qinputmethod.h>
15#include <QtGui/qguiapplication.h>
16#include <QtGui/private/qguiapplication_p.h>
17#include <QtGui/qpa/qplatformtheme.h>
18#include <QtQml/qjsvalue.h>
19#include <QtQml/qqmlcontext.h>
20#include <QtQml/private/qlazilyallocated_p.h>
21#include <private/qqmldelegatemodel_p.h>
22#include <QtQuick/private/qquickaccessibleattached_p.h>
23#include <QtQuick/private/qquickevents_p_p.h>
24#include <QtQuick/private/qquicktextinput_p.h>
25#include <QtQuick/private/qquicktextinput_p_p.h>
26#if QT_CONFIG(quick_itemview)
27#include <QtQuick/private/qquickitemview_p.h>
28#endif
29
31
32Q_LOGGING_CATEGORY(lcCalculateWidestTextWidth, "qt.quick.controls.combobox.calculatewidesttextwidth")
33
34
38
161namespace {
164}
165
166// ### Qt7: Remove this class. Use QQmlDelegateModel instead.
168{
169public:
171 QVariant variantValue(int index, const QString &role) override;
172
173private:
174 QQuickComboBox *combo = nullptr;
175};
176
178 : QQmlDelegateModel(qmlContext(combo), combo),
179 combo(combo)
180{
181}
182
184{
185 // ### Qt7: Get rid of this. Why do we special case lists of variant maps with
186 // exactly one entry? There are many other ways of producing a list of
187 // map-like things with exactly one entry. And what if some of the maps
188 // in the list have more than one entry? You get inconsistent results.
189 if (role == QLatin1String("modelData")) {
190 const QVariant model = combo->model();
191 if (model.metaType() == QMetaType::fromType<QVariantList>()) {
192 const QVariant object = model.toList().value(index);
193 if (object.metaType() == QMetaType::fromType<QVariantMap>()) {
194 const QVariantMap data = object.toMap();
195 if (data.size() == 1)
196 return data.first();
197 }
198 }
199 }
200
202}
203
205{
206public:
207 Q_DECLARE_PUBLIC(QQuickComboBox)
208
209 bool isPopupVisible() const;
210 void showPopup();
211 void hidePopup(bool accept);
212 void togglePopup(bool accept);
213 void popupVisibleChanged();
214
215 void itemClicked();
216 void itemHovered();
217
218 void createdItem(int index, QObject *object);
219 void modelUpdated();
220 void countChanged();
221
223 void updateEditText();
224 void updateCurrentText();
225 void updateCurrentValue();
228
229 bool isValidIndex(int index) const;
230
231 void acceptInput();
232 QString tryComplete(const QString &inputText);
233
236 void setCurrentIndex(int index, Activation activate);
238 void setHighlightedIndex(int index, Highlighting highlight);
239
240 void keySearch(const QString &text);
241 int match(int start, const QString &text, Qt::MatchFlags flags) const;
242
243 void createDelegateModel();
244
245 bool handlePress(const QPointF &point, ulong timestamp) override;
246 bool handleMove(const QPointF &point, ulong timestamp) override;
247 bool handleRelease(const QPointF &point, ulong timestamp) override;
248 void handleUngrab() override;
249
250 void cancelIndicator();
251 void executeIndicator(bool complete = false);
252
253 void cancelPopup();
254 void executePopup(bool complete = false);
255
258
259 void setInputMethodHints(Qt::InputMethodHints hints, bool force = false);
260
261 virtual qreal getContentWidth() const override;
264
265 static void hideOldPopup(QQuickPopup *popup);
266
268
269 bool flat = false;
270 bool down = false;
271 bool hasDown = false;
272 bool pressed = false;
273 bool ownModel = false;
274 bool keyNavigating = false;
275 bool hasDisplayText = false;
276 bool hasCurrentIndex = false;
279 int currentIndex = -1;
292 bool m_acceptableInput = true;
293
294 struct ExtraData {
295 bool editable = false;
296 bool accepting = false;
297 bool allowComplete = false;
298 bool selectTextByMouse = false;
299 Qt::InputMethodHints inputMethodHints = Qt::ImhNone;
301#if QT_CONFIG(validator)
302 QValidator *validator = nullptr;
303#endif
304 };
306};
307
309{
310 return popup && popup->isVisible();
311}
312
314{
315 if (!popup)
316 executePopup(true);
317
318 if (popup && !popup->isVisible())
319 popup->open();
320}
321
323{
324 Q_Q(QQuickComboBox);
325 if (accept) {
326 q->setCurrentIndex(highlightedIndex);
327 emit q->activated(currentIndex);
328 }
329 if (popup && popup->isVisible())
330 popup->close();
331}
332
334{
335 if (!popup || !popup->isVisible())
336 showPopup();
337 else
338 hidePopup(accept);
339}
340
342{
343 Q_Q(QQuickComboBox);
344 if (isPopupVisible())
346
347#if QT_CONFIG(quick_itemview)
349 if (itemView)
351#endif
352
354
355#if QT_CONFIG(quick_itemview)
356 if (itemView)
358#endif
359
360 if (!hasDown) {
361 q->setDown(pressed || isPopupVisible());
362 hasDown = false;
363 }
364}
365
367{
368 Q_Q(QQuickComboBox);
369 int index = delegateModel->indexOf(q->sender(), nullptr);
370 if (index != -1) {
371 setHighlightedIndex(index, Highlight);
372 hidePopup(true);
373 }
374}
375
377{
378 Q_Q(QQuickComboBox);
379 if (keyNavigating)
380 return;
381
382 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(q->sender());
383 if (!button || !button->isHovered() || !button->isEnabled() || QQuickAbstractButtonPrivate::get(button)->touchId != -1)
384 return;
385
386 int index = delegateModel->indexOf(button, nullptr);
387 if (index != -1) {
388 setHighlightedIndex(index, Highlight);
389
390#if QT_CONFIG(quick_itemview)
391 if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>())
392 itemView->positionViewAtIndex(index, QQuickItemView::Contain);
393#endif
394 }
395}
396
398{
399 Q_Q(QQuickComboBox);
401 if (item && !item->parentItem()) {
402 if (popup)
404 else
407 }
408
409 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(object);
410 if (button) {
414 }
415
416 if (index == currentIndex && !q->isEditable())
418}
419
421{
422 if (componentComplete && (!extra.isAllocated() || !extra->accepting)) {
424
427 }
428}
429
431{
432 Q_Q(QQuickComboBox);
433 if (q->count() == 0)
434 q->setCurrentIndex(-1);
435 emit q->countChanged();
436}
437
439{
440 return textRole.isEmpty() ? QStringLiteral("modelData") : textRole;
441}
442
444{
445 Q_Q(QQuickComboBox);
446 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(contentItem);
447 if (!input)
448 return;
449
450 const QString text = input->text();
451
452 if (extra.isAllocated() && extra->allowComplete && !text.isEmpty()) {
453 const QString completed = tryComplete(text);
454 if (completed.size() > text.size()) {
455 input->setText(completed);
456 // This will select the text backwards.
457 input->select(completed.size(), text.size());
458 return;
459 }
460 }
461 q->setEditText(text);
462}
463
465{
466 Q_Q(QQuickComboBox);
467 const QString text = q->textAt(currentIndex);
468 if (currentText != text) {
470 if (!hasDisplayText)
471 q->maybeSetAccessibleName(text);
472 emit q->currentTextChanged();
473 }
474 if (!hasDisplayText && displayText != text) {
476 emit q->displayTextChanged();
477 }
478 if (!extra.isAllocated() || !extra->accepting)
479 q->setEditText(currentText);
480}
481
483{
484 Q_Q(QQuickComboBox);
485 const QVariant value = q->valueAt(currentIndex);
486 if (currentValue == value)
487 return;
488
490 emit q->currentValueChanged();
491}
492
494{
497}
498
500{
501 Q_Q(QQuickComboBox);
502
503 if (!contentItem)
504 return;
505
506 const QQuickTextInput *textInputContentItem = qobject_cast<QQuickTextInput *>(contentItem);
507
508 if (!textInputContentItem)
509 return;
510
511 const bool newValue = textInputContentItem->hasAcceptableInput();
512
513 if (m_acceptableInput != newValue) {
514 m_acceptableInput = newValue;
515 emit q->acceptableInputChanged();
516 }
517}
518
520{
521 return delegateModel && index >= 0 && index < delegateModel->count();
522}
523
525{
526 Q_Q(QQuickComboBox);
527 int idx = q->find(extra.value().editText, Qt::MatchFixedString);
528 if (idx > -1) {
529 // The item that was accepted already exists, so make it the current item.
530 q->setCurrentIndex(idx);
531 // After accepting text that matches an existing entry, the selection should be cleared.
532 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(contentItem);
533 if (input) {
534 const auto text = input->text();
535 input->select(text.size(), text.size());
536 }
537 }
538
539 extra.value().accepting = true;
540 emit q->accepted();
541
542 // The user might have added the item since it didn't exist, so check again
543 // to see if we can select that new item.
544 if (idx == -1)
545 q->setCurrentIndex(q->find(extra.value().editText, Qt::MatchFixedString));
546 extra.value().accepting = false;
547}
548
550{
551 Q_Q(QQuickComboBox);
553
554 const int itemCount = q->count();
555 for (int idx = 0; idx < itemCount; ++idx) {
556 const QString text = q->textAt(idx);
558 continue;
559
560 // either the first or the shortest match
561 if (match.isEmpty() || text.size() < match.size())
562 match = text;
563 }
564
565 if (match.isEmpty())
566 return input;
567
568 return input + match.mid(input.size());
569}
570
571void QQuickComboBoxPrivate::setCurrentIndex(int index, Activation activate)
572{
573 Q_Q(QQuickComboBox);
574 if (currentIndex == index)
575 return;
576
578 emit q->currentIndexChanged();
579
582
583 if (activate)
584 emit q->activated(index);
585}
586
588{
589 Q_Q(QQuickComboBox);
590 if (extra.isAllocated())
591 extra->allowComplete = false;
592 if (isPopupVisible()) {
593 if (highlightedIndex < q->count() - 1)
595 } else {
596 if (currentIndex < q->count() - 1)
597 setCurrentIndex(currentIndex + 1, Activate);
598 }
599 if (extra.isAllocated())
600 extra->allowComplete = true;
601}
602
604{
605 if (extra.isAllocated())
606 extra->allowComplete = false;
607 if (isPopupVisible()) {
608 if (highlightedIndex > 0)
610 } else {
611 if (currentIndex > 0)
612 setCurrentIndex(currentIndex - 1, Activate);
613 }
614 if (extra.isAllocated())
615 extra->allowComplete = true;
616}
617
619{
620 setHighlightedIndex(popup->isVisible() ? currentIndex : -1, NoHighlight);
621}
622
623void QQuickComboBoxPrivate::setHighlightedIndex(int index, Highlighting highlight)
624{
625 Q_Q(QQuickComboBox);
626 if (highlightedIndex == index)
627 return;
628
630 emit q->highlightedIndexChanged();
631
632 if (highlight)
633 emit q->highlighted(index);
634}
635
637{
638 const int startIndex = isPopupVisible() ? highlightedIndex : currentIndex;
639 const int index = match(startIndex + 1, text, Qt::MatchStartsWith | Qt::MatchWrap);
640 if (index != -1) {
641 if (isPopupVisible())
642 setHighlightedIndex(index, Highlight);
643 else
644 setCurrentIndex(index, Activate);
645 }
646}
647
648int QQuickComboBoxPrivate::match(int start, const QString &text, Qt::MatchFlags flags) const
649{
650 Q_Q(const QQuickComboBox);
651 uint matchType = flags & 0x0F;
652 bool wrap = flags & Qt::MatchWrap;
654 QRegularExpression::PatternOptions options = flags & Qt::MatchCaseSensitive ? QRegularExpression::NoPatternOption
656 int from = start;
657 int to = q->count();
658
659 // iterates twice if wrapping
660 for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
661 for (int idx = from; idx < to; ++idx) {
662 QString t = q->textAt(idx);
663 switch (matchType) {
664 case Qt::MatchExactly:
665 if (t == text)
666 return idx;
667 break;
670 if (rx.match(t).hasMatch())
671 return idx;
672 break;
673 }
674 case Qt::MatchWildcard: {
676 options);
677 if (rx.match(t).hasMatch())
678 return idx;
679 break;
680 }
682 if (t.startsWith(text, cs))
683 return idx;
684 break;
686 if (t.endsWith(text, cs))
687 return idx;
688 break;
690 if (t.compare(text, cs) == 0)
691 return idx;
692 break;
694 default:
695 if (t.contains(text, cs))
696 return idx;
697 break;
698 }
699 }
700 // prepare for the next iteration
701 from = 0;
702 to = start;
703 }
704 return -1;
705}
706
708{
709 Q_Q(QQuickComboBox);
710 bool ownedOldModel = ownModel;
712 if (oldModel) {
716 }
717
718 ownModel = false;
720
721 if (!delegateModel && model.isValid()) {
723 dataModel->setModel(model);
724 dataModel->setDelegate(delegate);
725 if (q->isComponentComplete())
726 dataModel->componentComplete();
727
728 ownModel = true;
729 delegateModel = dataModel;
730 }
731
732 if (delegateModel) {
736 }
737
738 emit q->delegateModelChanged();
739
740 if (ownedOldModel)
741 delete oldModel;
742}
743
745{
746 Q_Q(QQuickComboBox);
747 QQuickControlPrivate::handlePress(point, timestamp);
748 q->setPressed(true);
749 return true;
750}
751
753{
754 Q_Q(QQuickComboBox);
755 QQuickControlPrivate::handleMove(point, timestamp);
756 q->setPressed(q->contains(point));
757 return true;
758}
759
761{
762 Q_Q(QQuickComboBox);
763 QQuickControlPrivate::handleRelease(point, timestamp);
764 if (pressed) {
765 q->setPressed(false);
766 togglePopup(false);
767 }
768 return true;
769}
770
772{
773 Q_Q(QQuickComboBox);
775 q->setPressed(false);
776}
777
779{
780 Q_Q(QQuickComboBox);
782}
783
785{
786 Q_Q(QQuickComboBox);
788 return;
789
790 if (!indicator || complete)
792 if (complete)
794}
795
796static inline QString popupName() { return QStringLiteral("popup"); }
797
799{
800 Q_Q(QQuickComboBox);
802}
803
805{
806 Q_Q(QQuickComboBox);
807 if (popup.wasExecuted())
808 return;
809
810 if (!popup || complete)
812 if (complete)
814}
815
817{
818 Q_Q(QQuickComboBox);
820 if (item == indicator)
821 emit q->implicitIndicatorWidthChanged();
822}
823
824void QQuickComboBoxPrivate::setInputMethodHints(Qt::InputMethodHints hints, bool force)
825{
826 Q_Q(QQuickComboBox);
827 if (!force && hints == q->inputMethodHints())
828 return;
829
830 extra.value().inputMethodHints = hints;
831 emit q->inputMethodHintsChanged();
832}
833
835{
836 Q_Q(QQuickComboBox);
838 if (item == indicator)
839 emit q->implicitIndicatorHeightChanged();
840}
841
843{
844 if (componentComplete) {
851 break;
852 default:
853 break;
854 }
855 }
856
858}
859
861{
862 Q_Q(const QQuickComboBox);
864 return 0;
865
866 const int count = q->count();
867 if (count == 0)
868 return 0;
869
870 auto textInput = qobject_cast<QQuickTextInput*>(contentItem);
871 if (!textInput)
872 return 0;
873
874 qCDebug(lcCalculateWidestTextWidth) << "calculating widest text from" << count << "items...";
875
876 // Avoid the index check and repeated calls to effectiveTextRole()
877 // that would result from calling textAt() in a loop.
879 auto textInputPrivate = QQuickTextInputPrivate::get(textInput);
880 qreal widest = 0;
881 for (int i = 0; i < count; ++i) {
883 const qreal textImplicitWidth = textInputPrivate->calculateImplicitWidthForText(text);
884 widest = qMax(widest, textImplicitWidth);
885 }
886
887 qCDebug(lcCalculateWidestTextWidth) << "... widest text is" << widest;
888 return widest;
889}
890
898{
900 return;
901
904 return;
905
908}
909
911{
912 if (!popup)
913 return;
914
915 qCDebug(lcItemManagement) << "hiding old popup" << popup;
916
917 popup->setVisible(false);
918 popup->setParentItem(nullptr);
919#if QT_CONFIG(accessibility)
920 // Remove the item from the accessibility tree.
921 QQuickAccessibleAttached *accessible = accessibleAttached(popup);
922 if (accessible)
923 accessible->setIgnored(true);
924#endif
925}
926
929{
933#if QT_CONFIG(cursor)
935#endif
936 Q_D(QQuickComboBox);
937 d->setInputMethodHints(Qt::ImhNoPredictiveText, true);
938}
939
941{
942 Q_D(QQuickComboBox);
943 d->removeImplicitSizeListener(d->indicator);
944 if (d->popup) {
945 // Disconnect visibleChanged() to avoid a spurious highlightedIndexChanged() signal
946 // emission during the destruction of the (visible) popup. (QTBUG-57650)
949 d->popup = nullptr;
950 }
951}
952
960{
961 Q_D(const QQuickComboBox);
962 return d->delegateModel ? d->delegateModel->count() : 0;
963}
964
984{
985 Q_D(const QQuickComboBox);
986 return d->model;
987}
988
990{
991 Q_D(QQuickComboBox);
992 QVariant model = m;
993 if (model.userType() == qMetaTypeId<QJSValue>())
995
996 if (d->model == model)
997 return;
998
999 if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(d->model)) {
1002 }
1003 if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(model)) {
1006 }
1007
1008 d->model = model;
1009 d->createDelegateModel();
1011 if (isComponentComplete()) {
1012 setCurrentIndex(count() > 0 ? 0 : -1);
1013 d->updateCurrentTextAndValue();
1014 }
1016
1017 d->maybeUpdateImplicitContentWidth();
1018}
1019
1027{
1028 Q_D(const QQuickComboBox);
1029 return d->delegateModel;
1030}
1031
1032
1043{
1044 Q_D(const QQuickComboBox);
1045 return d->pressed;
1046}
1047
1049{
1050 Q_D(QQuickComboBox);
1051 if (d->pressed == pressed)
1052 return;
1053
1054 d->pressed = pressed;
1056
1057 if (!d->hasDown) {
1058 setDown(d->pressed || d->isPopupVisible());
1059 d->hasDown = false;
1060 }
1061}
1062
1076{
1077 Q_D(const QQuickComboBox);
1078 return d->highlightedIndex;
1079}
1080
1091{
1092 Q_D(const QQuickComboBox);
1093 return d->currentIndex;
1094}
1095
1097{
1098 Q_D(QQuickComboBox);
1099 d->hasCurrentIndex = true;
1100 d->setCurrentIndex(index, NoActivate);
1101}
1102
1112{
1113 Q_D(const QQuickComboBox);
1114 return d->currentText;
1115}
1116
1137{
1138 Q_D(const QQuickComboBox);
1139 return d->displayText;
1140}
1141
1143{
1144 Q_D(QQuickComboBox);
1145 d->hasDisplayText = true;
1146 if (d->displayText == text)
1147 return;
1148
1149 d->displayText = text;
1152}
1153
1155{
1156 Q_D(QQuickComboBox);
1157 if (!d->hasDisplayText)
1158 return;
1159
1160 d->hasDisplayText = false;
1161 d->updateCurrentText();
1162}
1163
1164
1176{
1177 Q_D(const QQuickComboBox);
1178 return d->textRole;
1179}
1180
1182{
1183 Q_D(QQuickComboBox);
1184 if (d->textRole == role)
1185 return;
1186
1187 d->textRole = role;
1188 if (isComponentComplete())
1189 d->updateCurrentText();
1191}
1192
1205{
1206 Q_D(const QQuickComboBox);
1207 return d->valueRole;
1208}
1209
1211{
1212 Q_D(QQuickComboBox);
1213 if (d->valueRole == role)
1214 return;
1215
1216 d->valueRole = role;
1217 if (isComponentComplete())
1218 d->updateCurrentValue();
1219 emit valueRoleChanged();
1220}
1221
1246{
1247 Q_D(const QQuickComboBox);
1248 return d->delegate;
1249}
1250
1252{
1253 Q_D(QQuickComboBox);
1254 if (d->delegate == delegate)
1255 return;
1256
1257 delete d->delegate;
1258 d->delegate = delegate;
1259 QQmlDelegateModel *delegateModel = qobject_cast<QQmlDelegateModel*>(d->delegateModel);
1260 if (delegateModel)
1261 delegateModel->setDelegate(d->delegate);
1263}
1264
1273{
1274 QQuickComboBoxPrivate *d = const_cast<QQuickComboBoxPrivate *>(d_func());
1275 if (!d->indicator)
1276 d->executeIndicator();
1277 return d->indicator;
1278}
1279
1281{
1282 Q_D(QQuickComboBox);
1283 if (d->indicator == indicator)
1284 return;
1285
1287
1288 if (!d->indicator.isExecuting())
1289 d->cancelIndicator();
1290
1291 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
1292 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
1293
1294 d->removeImplicitSizeListener(d->indicator);
1296 d->indicator = indicator;
1297 if (indicator) {
1298 if (!indicator->parentItem())
1299 indicator->setParentItem(this);
1300 d->addImplicitSizeListener(indicator);
1301 }
1302
1303 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
1304 emit implicitIndicatorWidthChanged();
1305 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
1306 emit implicitIndicatorHeightChanged();
1307 if (!d->indicator.isExecuting())
1309}
1310
1325{
1326 QQuickComboBoxPrivate *d = const_cast<QQuickComboBoxPrivate *>(d_func());
1327 if (!d->popup)
1328 d->executePopup(isComponentComplete());
1329 return d->popup;
1330}
1331
1333{
1334 Q_D(QQuickComboBox);
1335 if (d->popup == popup)
1336 return;
1337
1338 if (!d->popup.isExecuting())
1339 d->cancelPopup();
1340
1341 if (d->popup) {
1344 }
1345 if (popup) {
1347 popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
1349
1350#if QT_CONFIG(quick_itemview)
1351 if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>())
1352 itemView->setHighlightRangeMode(QQuickItemView::NoHighlightRange);
1353#endif
1354 }
1355 d->popup = popup;
1356 if (!d->popup.isExecuting())
1358}
1359
1375{
1376 Q_D(const QQuickComboBox);
1377 return d->flat;
1378}
1379
1381{
1382 Q_D(QQuickComboBox);
1383 if (d->flat == flat)
1384 return;
1385
1386 d->flat = flat;
1387 emit flatChanged();
1388}
1389
1403{
1404 Q_D(const QQuickComboBox);
1405 return d->down;
1406}
1407
1409{
1410 Q_D(QQuickComboBox);
1411 d->hasDown = true;
1412
1413 if (d->down == down)
1414 return;
1415
1416 d->down = down;
1417 emit downChanged();
1418}
1419
1421{
1422 Q_D(QQuickComboBox);
1423 if (!d->hasDown)
1424 return;
1425
1426 setDown(d->pressed || d->isPopupVisible());
1427 d->hasDown = false;
1428}
1429
1441{
1442 Q_D(const QQuickComboBox);
1443 return d->extra.isAllocated() && d->extra->editable;
1444}
1445
1447{
1448 Q_D(QQuickComboBox);
1449 if (editable == isEditable())
1450 return;
1451
1452 if (d->contentItem) {
1453 if (editable) {
1454 d->contentItem->installEventFilter(this);
1455 if (QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem)) {
1458 }
1459#if QT_CONFIG(cursor)
1460 d->contentItem->setCursor(Qt::IBeamCursor);
1461#endif
1462 } else {
1463 d->contentItem->removeEventFilter(this);
1464 if (QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem)) {
1467 }
1468#if QT_CONFIG(cursor)
1469 d->contentItem->unsetCursor();
1470#endif
1471 }
1472 }
1473
1474 d->extra.value().editable = editable;
1475 setAccessibleProperty("editable", editable);
1476 emit editableChanged();
1477}
1478
1488{
1489 Q_D(const QQuickComboBox);
1490 return d->extra.isAllocated() ? d->extra->editText : QString();
1491}
1492
1494{
1495 Q_D(QQuickComboBox);
1496 if (text == editText())
1497 return;
1498
1499 d->extra.value().editText = text;
1500 emit editTextChanged();
1501}
1502
1504{
1506}
1507
1508#if QT_CONFIG(validator)
1538QValidator *QQuickComboBox::validator() const
1539{
1540 Q_D(const QQuickComboBox);
1541 return d->extra.isAllocated() ? d->extra->validator : nullptr;
1542}
1543
1544void QQuickComboBox::setValidator(QValidator *validator)
1545{
1546 Q_D(QQuickComboBox);
1547 if (validator == QQuickComboBox::validator())
1548 return;
1549
1550 d->extra.value().validator = validator;
1551#if QT_CONFIG(validator)
1552 if (validator)
1553 validator->setLocale(d->locale);
1554#endif
1555 emit validatorChanged();
1556}
1557#endif
1558
1570Qt::InputMethodHints QQuickComboBox::inputMethodHints() const
1571{
1572 Q_D(const QQuickComboBox);
1573 return d->extra.isAllocated() ? d->extra->inputMethodHints : Qt::ImhNoPredictiveText;
1574}
1575
1576void QQuickComboBox::setInputMethodHints(Qt::InputMethodHints hints)
1577{
1578 Q_D(QQuickComboBox);
1579 d->setInputMethodHints(hints);
1580}
1581
1594{
1595 Q_D(const QQuickComboBox);
1596 return d->contentItem && d->contentItem->property("inputMethodComposing").toBool();
1597}
1598
1612{
1613 Q_D(const QQuickComboBox);
1614 return d->m_acceptableInput;
1615}
1616
1632{
1633 Q_D(const QQuickComboBox);
1634 if (!d->indicator)
1635 return 0;
1636 return d->indicator->implicitWidth();
1637}
1638
1654{
1655 Q_D(const QQuickComboBox);
1656 if (!d->indicator)
1657 return 0;
1658 return d->indicator->implicitHeight();
1659}
1660
1673{
1674 Q_D(const QQuickComboBox);
1675 return d->currentValue;
1676}
1677
1687QVariant QQuickComboBox::valueAt(int index) const
1688{
1689 Q_D(const QQuickComboBox);
1690 if (!d->isValidIndex(index))
1691 return QVariant();
1692
1693 const QString effectiveValueRole = d->valueRole.isEmpty() ? QStringLiteral("modelData") : d->valueRole;
1694 return d->delegateModel->variantValue(index, effectiveValueRole);
1695}
1696
1709int QQuickComboBox::indexOfValue(const QVariant &value) const
1710{
1711 for (int i = 0; i < count(); ++i) {
1712 const QVariant ourValue = valueAt(i);
1713 if (value == ourValue)
1714 return i;
1715 }
1716 return -1;
1717}
1718
1729{
1730 Q_D(const QQuickComboBox);
1731 return d->extra.isAllocated() ? d->extra->selectTextByMouse : false;
1732}
1733
1735{
1736 Q_D(QQuickComboBox);
1737 if (canSelect == selectTextByMouse())
1738 return;
1739
1740 d->extra.value().selectTextByMouse = canSelect;
1741 emit selectTextByMouseChanged();
1742}
1743
1799{
1800 Q_D(const QQuickComboBox);
1801 return d->implicitContentWidthPolicy;
1802}
1803
1805{
1806 Q_D(QQuickComboBox);
1807 if (policy == d->implicitContentWidthPolicy)
1808 return;
1809
1810 d->implicitContentWidthPolicy = policy;
1811 d->maybeUpdateImplicitContentWidth();
1812 emit implicitContentWidthPolicyChanged();
1813}
1827{
1828 Q_D(const QQuickComboBox);
1829 if (!d->isValidIndex(index))
1830 return QString();
1831
1832 return d->delegateModel->stringValue(index, d->effectiveTextRole());
1833}
1834
1859int QQuickComboBox::find(const QString &text, Qt::MatchFlags flags) const
1860{
1861 Q_D(const QQuickComboBox);
1862 return d->match(0, text, flags);
1863}
1864
1874{
1875 Q_D(QQuickComboBox);
1876 d->incrementCurrentIndex();
1877}
1878
1888{
1889 Q_D(QQuickComboBox);
1890 d->decrementCurrentIndex();
1891}
1892
1901void QQuickComboBox::selectAll()
1902{
1903 Q_D(QQuickComboBox);
1904 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem);
1905 if (!input)
1906 return;
1907 input->selectAll();
1908}
1909
1911{
1912 Q_D(QQuickComboBox);
1913 switch (event->type()) {
1915 if (d->isPopupVisible())
1916 d->hidePopup(false);
1917 break;
1918 case QEvent::KeyPress: {
1919 QKeyEvent *ke = static_cast<QKeyEvent *>(event);
1920 if (d->filterKeyEvent(ke, false))
1921 return true;
1922 event->accept();
1923 if (d->extra.isAllocated())
1924 d->extra->allowComplete = ke->key() != Qt::Key_Backspace && ke->key() != Qt::Key_Delete;
1925 break;
1926 }
1927 case QEvent::FocusOut:
1928 if (qGuiApp->focusObject() != this && (!d->popup || !d->popup->hasActiveFocus())) {
1929 // Only close the popup if focus was transferred somewhere else
1930 // than to the popup or the popup button (which normally means that
1931 // the user clicked on the popup button to open it, not close it).
1932 d->hidePopup(false);
1933 setPressed(false);
1934
1935 // The focus left the text field, so if the edit text matches an item in the model,
1936 // change our currentIndex to that. This matches widgets' behavior.
1937 const int indexForEditText = find(d->extra.value().editText, Qt::MatchFixedString);
1938 if (indexForEditText > -1)
1939 setCurrentIndex(indexForEditText);
1940 }
1941 break;
1942#if QT_CONFIG(im)
1944 if (d->extra.isAllocated())
1945 d->extra->allowComplete = !static_cast<QInputMethodEvent*>(event)->commitString().isEmpty();
1946 break;
1947#endif
1948 default:
1949 break;
1950 }
1951 return QQuickControl::eventFilter(object, event);
1952}
1953
1955{
1956 Q_D(QQuickComboBox);
1958 // Setting focus on TextField should not be done when drop down indicator was clicked
1959 // That is why, if focus is not set with key reason, it should not be passed to textEdit by default.
1960 // Focus on Edit Text should be set only intentionally by user.
1961 if ((event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ||
1962 event->reason() == Qt::ShortcutFocusReason) && d->contentItem && isEditable())
1963 d->contentItem->forceActiveFocus(event->reason());
1964}
1965
1967{
1968 Q_D(QQuickComboBox);
1970
1971 if (qGuiApp->focusObject() != d->contentItem && (!d->popup || !d->popup->hasActiveFocus())) {
1972 // Only close the popup if focus was transferred
1973 // somewhere else than to the popup or the inner line edit (which is
1974 // normally done from QQuickComboBox::focusInEvent).
1975 d->hidePopup(false);
1976 setPressed(false);
1977 }
1978}
1979
1980#if QT_CONFIG(im)
1981void QQuickComboBox::inputMethodEvent(QInputMethodEvent *event)
1982{
1983 Q_D(QQuickComboBox);
1984 QQuickControl::inputMethodEvent(event);
1985 if (!isEditable() && !event->commitString().isEmpty())
1986 d->keySearch(event->commitString());
1987 else
1988 event->ignore();
1989}
1990#endif
1991
1993{
1994 Q_D(QQuickComboBox);
1996
1997 const auto key = event->key();
1998 if (!isEditable()) {
2000 if (buttonPressKeys.contains(key)) {
2001 if (!event->isAutoRepeat())
2002 setPressed(true);
2003 event->accept();
2004 return;
2005 }
2006 }
2007
2008 switch (key) {
2009 case Qt::Key_Escape:
2010 case Qt::Key_Back:
2011 if (d->isPopupVisible())
2012 event->accept();
2013 break;
2014 case Qt::Key_Enter:
2015 case Qt::Key_Return:
2016 if (d->isPopupVisible())
2017 setPressed(true);
2018 event->accept();
2019 break;
2020 case Qt::Key_Up:
2021 d->keyNavigating = true;
2022 d->decrementCurrentIndex();
2023 event->accept();
2024 break;
2025 case Qt::Key_Down:
2026 d->keyNavigating = true;
2027 d->incrementCurrentIndex();
2028 event->accept();
2029 break;
2030 case Qt::Key_Home:
2031 d->keyNavigating = true;
2032 if (d->isPopupVisible())
2033 d->setHighlightedIndex(0, Highlight);
2034 else
2035 d->setCurrentIndex(0, Activate);
2036 event->accept();
2037 break;
2038 case Qt::Key_End:
2039 d->keyNavigating = true;
2040 if (d->isPopupVisible())
2041 d->setHighlightedIndex(count() - 1, Highlight);
2042 else
2043 d->setCurrentIndex(count() - 1, Activate);
2044 event->accept();
2045 break;
2046 default:
2047 if (!isEditable() && !event->text().isEmpty())
2048 d->keySearch(event->text());
2049 else
2050 event->ignore();
2051 break;
2052 }
2053}
2054
2056{
2057 Q_D(QQuickComboBox);
2059 d->keyNavigating = false;
2060 if (event->isAutoRepeat())
2061 return;
2062
2063 const auto key = event->key();
2064 if (!isEditable()) {
2066 if (buttonPressKeys.contains(key)) {
2067 if (!isEditable() && isPressed())
2068 d->togglePopup(true);
2069 setPressed(false);
2070 event->accept();
2071 return;
2072 }
2073 }
2074
2075 switch (key) {
2076 case Qt::Key_Enter:
2077 case Qt::Key_Return:
2078 if (!isEditable() || d->isPopupVisible())
2079 d->hidePopup(d->isPopupVisible());
2080 setPressed(false);
2081 event->accept();
2082 break;
2083 case Qt::Key_Escape:
2084 case Qt::Key_Back:
2085 if (d->isPopupVisible()) {
2086 d->hidePopup(false);
2087 setPressed(false);
2088 event->accept();
2089 }
2090 break;
2091 default:
2092 break;
2093 }
2094}
2095
2096#if QT_CONFIG(wheelevent)
2097void QQuickComboBox::wheelEvent(QWheelEvent *event)
2098{
2099 Q_D(QQuickComboBox);
2100 QQuickControl::wheelEvent(event);
2101 if (d->wheelEnabled && !d->isPopupVisible()) {
2102 if (event->angleDelta().y() > 0)
2103 d->decrementCurrentIndex();
2104 else
2105 d->incrementCurrentIndex();
2106 }
2107}
2108#endif
2109
2111{
2112 Q_D(QQuickComboBox);
2113 if (e->type() == QEvent::LanguageChange)
2114 d->updateCurrentTextAndValue();
2115 return QQuickControl::event(e);
2116}
2117
2119{
2120 Q_D(QQuickComboBox);
2121 d->executeIndicator(true);
2123 if (d->popup)
2124 d->executePopup(true);
2125
2126 if (d->delegateModel && d->ownModel)
2127 static_cast<QQmlDelegateModel *>(d->delegateModel)->componentComplete();
2128
2129 if (count() > 0) {
2130 if (!d->hasCurrentIndex && d->currentIndex == -1)
2131 setCurrentIndex(0);
2132 else
2133 d->updateCurrentTextAndValue();
2134
2135 // If the widest text was already calculated in the call to
2136 // QQmlDelegateModel::componentComplete() above, then we shouldn't do it here too.
2137 if (!d->hasCalculatedWidestText)
2138 d->maybeUpdateImplicitContentWidth();
2139 }
2140}
2141
2143{
2144 Q_D(QQuickComboBox);
2146 if (change == ItemVisibleHasChanged && !value.boolValue) {
2147 d->hidePopup(false);
2148 setPressed(false);
2149 }
2150}
2151
2152void QQuickComboBox::fontChange(const QFont &newFont, const QFont &oldFont)
2153{
2154 Q_D(QQuickComboBox);
2155 QQuickControl::fontChange(newFont, oldFont);
2156 d->maybeUpdateImplicitContentWidth();
2157}
2158
2160{
2161 Q_D(QQuickComboBox);
2162 if (oldItem) {
2163 oldItem->removeEventFilter(this);
2164 if (QQuickTextInput *oldInput = qobject_cast<QQuickTextInput *>(oldItem)) {
2167 disconnect(oldInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickComboBox::inputMethodComposingChanged);
2169 }
2170 }
2171 if (newItem && isEditable()) {
2172 newItem->installEventFilter(this);
2173 if (QQuickTextInput *newInput = qobject_cast<QQuickTextInput *>(newItem)) {
2176 connect(newInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickComboBox::inputMethodComposingChanged);
2178 }
2179#if QT_CONFIG(cursor)
2180 newItem->setCursor(Qt::IBeamCursor);
2181#endif
2182 }
2183
2184 d->updateAcceptableInput();
2185}
2186
2187void QQuickComboBox::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
2188{
2189 QQuickControl::localeChange(newLocale, oldLocale);
2190#if QT_CONFIG(validator)
2191 if (QValidator *v = validator())
2192 v->setLocale(newLocale);
2193#endif
2194}
2195
2197{
2199}
2200
2201#if QT_CONFIG(accessibility)
2202QAccessible::Role QQuickComboBox::accessibleRole() const
2203{
2204 return QAccessible::ComboBox;
2205}
2206
2207void QQuickComboBox::accessibilityActiveChanged(bool active)
2208{
2209 Q_D(QQuickComboBox);
2210 QQuickControl::accessibilityActiveChanged(active);
2211
2212 if (active) {
2213 maybeSetAccessibleName(d->hasDisplayText ? d->displayText : d->currentText);
2214 setAccessibleProperty("editable", isEditable());
2215 }
2216}
2217#endif //
2218
2220
2221#include "moc_qquickcombobox_p.cpp"
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.
\inmodule QtCore
Definition qcoreevent.h:45
@ FocusOut
Definition qcoreevent.h:67
@ InputMethod
Definition qcoreevent.h:120
@ KeyPress
Definition qcoreevent.h:64
@ LanguageChange
Definition qcoreevent.h:123
@ MouseButtonRelease
Definition qcoreevent.h:61
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:305
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant
Definition qfont.h:20
void setParentItem(QGraphicsItem *parent)
Sets this item's parent item to newParent.
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
static QPlatformTheme * platformTheme()
static QInputMethod * inputMethod()
returns the input method.
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
void reset()
Resets the input method state.
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
The QKeyEvent class describes a key event.
Definition qevent.h:423
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
Definition qlist.h:74
T value(qsizetype i) const
Definition qlist.h:661
T & first()
Definition qmap.h:418
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:298
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
Definition qobject_p.h:327
\inmodule QtCore
Definition qobject.h:90
T findChild(const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
Definition qobject.h:133
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
Definition qobject.cpp:2269
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1363
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
Definition qobject.cpp:1518
void removeEventFilter(QObject *obj)
Removes an event filter object obj from this object.
Definition qobject.cpp:2300
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
virtual QVariant themeHint(ThemeHint hint) const
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QQmlComponent class encapsulates a QML component definition.
void setModel(const QVariant &)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setDelegate(QQmlComponent *)
QVariant variantValue(int index, const QString &role) override
void createdItem(int index, QObject *object)
void modelUpdated(const QQmlChangeSet &changeSet, bool reset)
virtual int indexOf(QObject *object, QObject *objectContext) const =0
QString stringValue(int index, const QString &role)
static QQuickAbstractButtonPrivate * get(QQuickAbstractButton *button)
QQuickComboBoxDelegateModel(QQuickComboBox *combo)
QVariant variantValue(int index, const QString &role) override
bool handleRelease(const QPointF &point, ulong timestamp) override
qreal calculateWidestTextWidth() const
QQmlInstanceModel * delegateModel
static void hideOldPopup(QQuickPopup *popup)
void setInputMethodHints(Qt::InputMethodHints hints, bool force=false)
void setHighlightedIndex(int index, Highlighting highlight)
void createdItem(int index, QObject *object)
QString effectiveTextRole() const
QLazilyAllocated< ExtraData > extra
virtual qreal getContentWidth() const override
void keySearch(const QString &text)
void handleUngrab() override
int match(int start, const QString &text, Qt::MatchFlags flags) const
void setCurrentIndex(int index, Activation activate)
QQuickComboBox::ImplicitContentWidthPolicy implicitContentWidthPolicy
QPalette defaultPalette() const override
QQuickDeferredPointer< QQuickPopup > popup
bool handleMove(const QPointF &point, ulong timestamp) override
void itemImplicitHeightChanged(QQuickItem *item) override
void togglePopup(bool accept)
void executePopup(bool complete=false)
void itemImplicitWidthChanged(QQuickItem *item) override
QQuickDeferredPointer< QQuickItem > indicator
void executeIndicator(bool complete=false)
void hidePopup(bool accept)
bool handlePress(const QPointF &point, ulong timestamp) override
bool isValidIndex(int index) const
QString tryComplete(const QString &inputText)
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override
QQmlInstanceModel * delegateModel
void delegateChanged()
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setSelectTextByMouse(bool canSelect)
bool isDown() const
bool isEditable() const
qreal implicitIndicatorHeight
void setValueRole(const QString &role)
void setDisplayText(const QString &text)
void setEditText(const QString &text)
QQmlComponent * delegate
QQuickComboBox(QQuickItem *parent=nullptr)
void setInputMethodHints(Qt::InputMethodHints hints)
void countChanged()
void fontChange(const QFont &newFont, const QFont &oldFont) override
void setIndicator(QQuickItem *indicator)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void setModel(const QVariant &model)
void focusInEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void incrementCurrentIndex()
\qmlmethod void QtQuick.Controls::ComboBox::incrementCurrentIndex()
bool eventFilter(QObject *object, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
void setDelegate(QQmlComponent *delegate)
bool isPressed() const
\readonly \qmlproperty bool QtQuick.Controls::ComboBox::pressed
void setPopup(QQuickPopup *popup)
void focusOutEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
void setCurrentIndex(int index)
void setEditable(bool editable)
bool hasAcceptableInput() const
void popupChanged()
Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags=Qt::MatchExactly) const
\qmlmethod int QtQuick.Controls::ComboBox::find(string text, enumeration flags)
QFont defaultFont() const override
void textRoleChanged()
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
void displayTextChanged()
QQuickPopup * popup
void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy)
ImplicitContentWidthPolicy implicitContentWidthPolicy
QQuickItem * indicator
void setFlat(bool flat)
void setTextRole(const QString &role)
bool isFlat() const
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
void setDown(bool down)
Q_INVOKABLE QString textAt(int index) const
\qmlmethod string QtQuick.Controls::ComboBox::textAt(int index)
Qt::InputMethodHints inputMethodHints
void indicatorChanged()
void setPressed(bool pressed)
void decrementCurrentIndex()
\qmlmethod void QtQuick.Controls::ComboBox::decrementCurrentIndex()
void modelChanged()
void pressedChanged()
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
bool isInputMethodComposing() const
void itemImplicitWidthChanged(QQuickItem *item) override
virtual bool handlePress(const QPointF &point, ulong timestamp)
QQuickDeferredPointer< QQuickItem > contentItem
static void hideOldItem(QQuickItem *item)
virtual void handleUngrab()
virtual bool handleRelease(const QPointF &point, ulong timestamp)
virtual qreal getContentWidth() const
static void warnIfCustomizationNotSupported(QObject *control, QQuickItem *item, const QString &propertyName)
virtual bool handleMove(const QPointF &point, ulong timestamp)
void itemImplicitHeightChanged(QQuickItem *item) override
void focusInEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void maybeSetAccessibleName(const QString &name)
virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale)
void setFocusPolicy(Qt::FocusPolicy policy)
void hoveredChanged()
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
bool setAccessibleProperty(const char *propertyName, const QVariant &value)
void focusOutEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
virtual void fontChange(const QFont &newFont, const QFont &oldFont)
quint32 componentComplete
static QQuickItemPrivate * get(QQuickItem *item)
Q_INVOKABLE void positionViewAtIndex(int index, int mode)
void setHighlightRangeMode(HighlightRangeMode mode)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
void setParentItem(QQuickItem *parent)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
QQuickItem * parentItem() const
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
@ ItemVisibleHasChanged
Definition qquickitem.h:147
static QQuickPopupPrivate * get(QQuickPopup *popup)
void visibleChanged()
void close()
\qmlmethod void QtQuick.Controls::Popup::close()
void open()
\qmlmethod void QtQuick.Controls::Popup::open()
virtual void setVisible(bool visible)
QQuickItem * contentItem
static QQuickTextInputPrivate * get(QQuickTextInput *t)
void inputMethodComposingChanged()
bool hasAcceptableInput() const
\qmlproperty bool QtQuick::TextInput::acceptableInput \readonly
void acceptableInputChanged()
static QPalette palette(Scope scope)
static QFont font(Scope scope)
\inmodule QtCore \reentrant
static QString anchoredPattern(const QString &expression)
static QString wildcardToRegularExpression(const QString &str, WildcardConversionOptions options=DefaultWildcardConversion)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5299
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
The QValidator class provides validation of input text.
Definition qvalidator.h:24
void setLocale(const QLocale &locale)
Sets the locale that will be used for the validator.
\inmodule QtCore
Definition qvariant.h:64
T value() const &
Definition qvariant.h:511
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:707
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has userType() \l QMetaType::QVariantList.
int userType() const
Definition qvariant.h:336
QMetaType metaType() const
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7904
bool isEnabled() const
Definition qwidget.h:814
QString text
QPushButton * button
[2]
double e
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:57
@ NoFocus
Definition qnamespace.h:106
@ StrongFocus
Definition qnamespace.h:109
@ ArrowCursor
@ IBeamCursor
@ ImhNone
@ ImhNoPredictiveText
@ Key_Escape
Definition qnamespace.h:658
@ Key_Return
Definition qnamespace.h:662
@ Key_Enter
Definition qnamespace.h:663
@ Key_Backspace
Definition qnamespace.h:661
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_Delete
Definition qnamespace.h:665
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_End
Definition qnamespace.h:671
CaseSensitivity
@ CaseInsensitive
@ CaseSensitive
@ BacktabFocusReason
@ TabFocusReason
@ ShortcutFocusReason
@ MatchWildcard
@ MatchCaseSensitive
@ MatchExactly
@ MatchFixedString
@ MatchRegularExpression
@ MatchEndsWith
@ MatchWrap
@ MatchContains
@ MatchStartsWith
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:287
#define qGuiApp
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLuint64 key
GLuint index
[2]
GLenum GLenum GLsizei count
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
struct _cl_event * event
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLenum input
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:71
static QString popupName()
void quickCancelDeferred(QObject *object, const QString &property)
void quickCompleteDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
void quickBeginDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:483
static qreal valueAt(const QQuickRangeSlider *slider, qreal position)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define emit
static QString indicatorName()
unsigned long ulong
Definition qtypes.h:30
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols, V4ObjectSet *visitedObjects)
myObject disconnect()
[26]
p rx()++
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
QSizePolicy policy
Qt::InputMethodHints inputMethodHints
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
\inmodule QtQuick
Definition qquickitem.h:158