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
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
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 void popupDestroyed();
215
216 void itemClicked();
217 void itemHovered();
218
219 void createdItem(int index, QObject *object);
220 void modelUpdated();
221 void countChanged();
222
224 void updateEditText();
225 void updateCurrentText();
226 void updateCurrentValue();
229
230 bool isValidIndex(int index) const;
231
232 void acceptInput();
233 QString tryComplete(const QString &inputText);
234
237 void setCurrentIndex(int index, Activation activate);
239 void setHighlightedIndex(int index, Highlighting highlight);
240
241 void keySearch(const QString &text);
242 int match(int start, const QString &text, Qt::MatchFlags flags) const;
243
244 void createDelegateModel();
245
246 bool handlePress(const QPointF &point, ulong timestamp) override;
247 bool handleMove(const QPointF &point, ulong timestamp) override;
248 bool handleRelease(const QPointF &point, ulong timestamp) override;
249 void handleUngrab() override;
250
251 void cancelIndicator();
252 void executeIndicator(bool complete = false);
253
254 void cancelPopup();
255 void executePopup(bool complete = false);
256
259 void itemDestroyed(QQuickItem *item) override;
260
261 void setInputMethodHints(Qt::InputMethodHints hints, bool force = false);
262
263 virtual qreal getContentWidth() const override;
266
267 static void hideOldPopup(QQuickPopup *popup);
268
270
271 bool flat = false;
272 bool down = false;
273 bool hasDown = false;
274 bool pressed = false;
275 bool ownModel = false;
276 bool keyNavigating = false;
277 bool hasDisplayText = false;
278 bool hasCurrentIndex = false;
281 int currentIndex = -1;
292 QQuickDeferredPointer<QQuickItem> indicator;
293 QQuickDeferredPointer<QQuickPopup> popup;
294 bool m_acceptableInput = true;
295
296 struct ExtraData {
297 bool editable = false;
298 bool accepting = false;
299 bool allowComplete = false;
300 bool selectTextByMouse = false;
301 Qt::InputMethodHints inputMethodHints = Qt::ImhNone;
303#if QT_CONFIG(validator)
304 QValidator *validator = nullptr;
305#endif
306 };
307 QLazilyAllocated<ExtraData> extra;
308};
309
311{
312 return popup && popup->isVisible();
313}
314
316{
317 if (!popup)
318 executePopup(true);
319
320 if (popup && !popup->isVisible())
321 popup->open();
322}
323
325{
326 Q_Q(QQuickComboBox);
327 if (accept) {
328 q->setCurrentIndex(highlightedIndex);
329 emit q->activated(currentIndex);
330 }
331 if (popup && popup->isVisible())
332 popup->close();
333}
334
336{
337 if (!popup || !popup->isVisible())
338 showPopup();
339 else
340 hidePopup(accept);
341}
342
344{
345 Q_Q(QQuickComboBox);
346 if (isPopupVisible())
348
349#if QT_CONFIG(quick_itemview)
351 if (itemView)
353#endif
354
356
357#if QT_CONFIG(quick_itemview)
358 if (itemView)
360#endif
361
362 if (!hasDown) {
363 q->setDown(pressed || isPopupVisible());
364 hasDown = false;
365 }
366}
367
369{
370 Q_Q(QQuickComboBox);
371 popup = nullptr;
372 emit q->popupChanged();
373}
374
376{
377 Q_Q(QQuickComboBox);
378 int index = delegateModel->indexOf(q->sender(), nullptr);
379 if (index != -1) {
380 setHighlightedIndex(index, Highlight);
381 hidePopup(true);
382 }
383}
384
386{
387 Q_Q(QQuickComboBox);
388 if (keyNavigating)
389 return;
390
391 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(q->sender());
392 if (!button || !button->isHovered() || !button->isEnabled() || QQuickAbstractButtonPrivate::get(button)->touchId != -1)
393 return;
394
395 int index = delegateModel->indexOf(button, nullptr);
396 if (index != -1) {
397 setHighlightedIndex(index, Highlight);
398
399#if QT_CONFIG(quick_itemview)
400 if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>())
401 itemView->positionViewAtIndex(index, QQuickItemView::Contain);
402#endif
403 }
404}
405
407{
408 Q_Q(QQuickComboBox);
410 if (item && !item->parentItem()) {
411 if (popup)
413 else
415 QQuickItemPrivate::get(item)->setCulled(true);
416 }
417
418 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(object);
419 if (button) {
423 }
424
425 if (index == currentIndex && !q->isEditable())
427}
428
438
440{
441 Q_Q(QQuickComboBox);
442 if (q->count() == 0)
443 q->setCurrentIndex(-1);
444 emit q->countChanged();
445}
446
451
453{
454 Q_Q(QQuickComboBox);
455 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(contentItem);
456 if (!input)
457 return;
458
459 const QString text = input->text();
460
461 if (extra.isAllocated() && extra->allowComplete && !text.isEmpty()) {
462 const QString completed = tryComplete(text);
463 if (completed.size() > text.size()) {
464 input->setText(completed);
465 // This will select the text backwards.
466 input->select(completed.size(), text.size());
467 return;
468 }
469 }
470 q->setEditText(text);
471}
472
474{
475 Q_Q(QQuickComboBox);
476 const QString text = q->textAt(currentIndex);
477 if (currentText != text) {
479 if (!hasDisplayText)
480 q->maybeSetAccessibleName(text);
481 emit q->currentTextChanged();
482 }
483 if (!hasDisplayText && displayText != text) {
485 emit q->displayTextChanged();
486 }
487 if (!extra.isAllocated() || !extra->accepting)
488 q->setEditText(currentText);
489}
490
492{
493 Q_Q(QQuickComboBox);
494 const QVariant value = q->valueAt(currentIndex);
495 if (currentValue == value)
496 return;
497
499 emit q->currentValueChanged();
500}
501
507
509{
510 Q_Q(QQuickComboBox);
511
512 if (!contentItem)
513 return;
514
515 const QQuickTextInput *textInputContentItem = qobject_cast<QQuickTextInput *>(contentItem);
516
517 if (!textInputContentItem)
518 return;
519
520 const bool newValue = textInputContentItem->hasAcceptableInput();
521
522 if (m_acceptableInput != newValue) {
523 m_acceptableInput = newValue;
524 emit q->acceptableInputChanged();
525 }
526}
527
529{
530 return delegateModel && index >= 0 && index < delegateModel->count();
531}
532
534{
535 Q_Q(QQuickComboBox);
536 int idx = q->find(extra.value().editText, Qt::MatchFixedString);
537 if (idx > -1) {
538 // The item that was accepted already exists, so make it the current item.
539 q->setCurrentIndex(idx);
540 // After accepting text that matches an existing entry, the selection should be cleared.
541 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(contentItem);
542 if (input) {
543 const auto text = input->text();
544 input->select(text.size(), text.size());
545 }
546 }
547
548 extra.value().accepting = true;
549 emit q->accepted();
550
551 // The user might have added the item since it didn't exist, so check again
552 // to see if we can select that new item.
553 if (idx == -1)
554 q->setCurrentIndex(q->find(extra.value().editText, Qt::MatchFixedString));
555 extra.value().accepting = false;
556}
557
559{
560 Q_Q(QQuickComboBox);
562
563 const int itemCount = q->count();
564 for (int idx = 0; idx < itemCount; ++idx) {
565 const QString text = q->textAt(idx);
567 continue;
568
569 // either the first or the shortest match
570 if (match.isEmpty() || text.size() < match.size())
571 match = text;
572 }
573
574 if (match.isEmpty())
575 return input;
576
577 return input + match.mid(input.size());
578}
579
580void QQuickComboBoxPrivate::setCurrentIndex(int index, Activation activate)
581{
582 Q_Q(QQuickComboBox);
583 if (currentIndex == index)
584 return;
585
587 emit q->currentIndexChanged();
588
591
592 if (activate)
593 emit q->activated(index);
594}
595
597{
598 Q_Q(QQuickComboBox);
599 if (extra.isAllocated())
600 extra->allowComplete = false;
601 if (isPopupVisible()) {
602 if (highlightedIndex < q->count() - 1)
604 } else {
605 if (currentIndex < q->count() - 1)
606 setCurrentIndex(currentIndex + 1, Activate);
607 }
608 if (extra.isAllocated())
609 extra->allowComplete = true;
610}
611
613{
614 if (extra.isAllocated())
615 extra->allowComplete = false;
616 if (isPopupVisible()) {
617 if (highlightedIndex > 0)
619 } else {
620 if (currentIndex > 0)
621 setCurrentIndex(currentIndex - 1, Activate);
622 }
623 if (extra.isAllocated())
624 extra->allowComplete = true;
625}
626
628{
629 setHighlightedIndex(popup->isVisible() ? currentIndex : -1, NoHighlight);
630}
631
632void QQuickComboBoxPrivate::setHighlightedIndex(int index, Highlighting highlight)
633{
634 Q_Q(QQuickComboBox);
635 if (highlightedIndex == index)
636 return;
637
639 emit q->highlightedIndexChanged();
640
641 if (highlight)
642 emit q->highlighted(index);
643}
644
646{
647 const int startIndex = isPopupVisible() ? highlightedIndex : currentIndex;
648 const int index = match(startIndex + 1, text, Qt::MatchStartsWith | Qt::MatchWrap);
649 if (index != -1) {
650 if (isPopupVisible())
651 setHighlightedIndex(index, Highlight);
652 else
653 setCurrentIndex(index, Activate);
654 }
655}
656
657int QQuickComboBoxPrivate::match(int start, const QString &text, Qt::MatchFlags flags) const
658{
659 Q_Q(const QQuickComboBox);
660 uint matchType = flags & 0x0F;
661 bool wrap = flags & Qt::MatchWrap;
663 QRegularExpression::PatternOptions options = flags & Qt::MatchCaseSensitive ? QRegularExpression::NoPatternOption
665 int from = start;
666 int to = q->count();
667
668 // iterates twice if wrapping
669 for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
670 for (int idx = from; idx < to; ++idx) {
671 QString t = q->textAt(idx);
672 switch (matchType) {
673 case Qt::MatchExactly:
674 if (t == text)
675 return idx;
676 break;
679 if (rx.match(t).hasMatch())
680 return idx;
681 break;
682 }
683 case Qt::MatchWildcard: {
685 options);
686 if (rx.match(t).hasMatch())
687 return idx;
688 break;
689 }
691 if (t.startsWith(text, cs))
692 return idx;
693 break;
695 if (t.endsWith(text, cs))
696 return idx;
697 break;
699 if (t.compare(text, cs) == 0)
700 return idx;
701 break;
703 default:
704 if (t.contains(text, cs))
705 return idx;
706 break;
707 }
708 }
709 // prepare for the next iteration
710 from = 0;
711 to = start;
712 }
713 return -1;
714}
715
717{
718 Q_Q(QQuickComboBox);
719 bool ownedOldModel = ownModel;
721 if (oldModel) {
725 }
726
727 ownModel = false;
729
730 if (!delegateModel && model.isValid()) {
732 dataModel->setModel(model);
733 dataModel->setDelegate(delegate);
734 if (q->isComponentComplete())
735 dataModel->componentComplete();
736
737 ownModel = true;
738 delegateModel = dataModel;
739 }
740
741 if (delegateModel) {
745 }
746
747 emit q->delegateModelChanged();
748
749 if (ownedOldModel)
750 delete oldModel;
751}
752
754{
755 Q_Q(QQuickComboBox);
756 QQuickControlPrivate::handlePress(point, timestamp);
757 q->setPressed(true);
758 return true;
759}
760
762{
763 Q_Q(QQuickComboBox);
764 QQuickControlPrivate::handleMove(point, timestamp);
765 q->setPressed(q->contains(point));
766 return true;
767}
768
770{
771 Q_Q(QQuickComboBox);
772 QQuickControlPrivate::handleRelease(point, timestamp);
773 if (pressed) {
774 q->setPressed(false);
775 togglePopup(false);
776 }
777 return true;
778}
779
781{
782 Q_Q(QQuickComboBox);
784 q->setPressed(false);
785}
786
792
794{
795 Q_Q(QQuickComboBox);
797 return;
798
799 if (!indicator || complete)
801 if (complete)
803}
804
805static inline QString popupName() { return QStringLiteral("popup"); }
806
812
814{
815 Q_Q(QQuickComboBox);
816 if (popup.wasExecuted())
817 return;
818
819 if (!popup || complete)
821 if (complete)
823}
824
832
833void QQuickComboBoxPrivate::setInputMethodHints(Qt::InputMethodHints hints, bool force)
834{
835 Q_Q(QQuickComboBox);
836 if (!force && hints == q->inputMethodHints())
837 return;
838
839 extra.value().inputMethodHints = hints;
840 emit q->inputMethodHintsChanged();
841}
842
850
852{
853 Q_Q(QQuickComboBox);
855 if (item == indicator) {
856 indicator = nullptr;
857 emit q->indicatorChanged();
858 }
859}
860
862{
863 if (componentComplete) {
870 break;
871 default:
872 break;
873 }
874 }
875
877}
878
880{
881 Q_Q(const QQuickComboBox);
883 return 0;
884
885 const int count = q->count();
886 if (count == 0)
887 return 0;
888
889 auto textInput = qobject_cast<QQuickTextInput*>(contentItem);
890 if (!textInput)
891 return 0;
892
893 qCDebug(lcCalculateWidestTextWidth) << "calculating widest text from" << count << "items...";
894
895 // Avoid the index check and repeated calls to effectiveTextRole()
896 // that would result from calling textAt() in a loop.
898 auto textInputPrivate = QQuickTextInputPrivate::get(textInput);
899 qreal widest = 0;
900 for (int i = 0; i < count; ++i) {
902 const qreal textImplicitWidth = textInputPrivate->calculateImplicitWidthForText(text);
903 widest = qMax(widest, textImplicitWidth);
904 }
905
906 qCDebug(lcCalculateWidestTextWidth) << "... widest text is" << widest;
907 return widest;
908}
909
928
930{
931 if (!popup)
932 return;
933
934 qCDebug(lcItemManagement) << "hiding old popup" << popup;
935
936 popup->setVisible(false);
937 popup->setParentItem(nullptr);
938#if QT_CONFIG(accessibility)
939 // Remove the item from the accessibility tree.
940 QQuickAccessibleAttached *accessible = accessibleAttached(popup);
941 if (accessible)
942 accessible->setIgnored(true);
943#endif
944}
945
959
961{
962 Q_D(QQuickComboBox);
963 d->removeImplicitSizeListener(d->indicator);
964 if (d->popup) {
965 // Disconnect visibleChanged() to avoid a spurious highlightedIndexChanged() signal
966 // emission during the destruction of the (visible) popup. (QTBUG-57650)
969 d->popup = nullptr;
970 }
971}
972
980{
981 Q_D(const QQuickComboBox);
982 return d->delegateModel ? d->delegateModel->count() : 0;
983}
984
1004{
1005 Q_D(const QQuickComboBox);
1006 return d->model;
1007}
1008
1010{
1011 Q_D(QQuickComboBox);
1012 QVariant model = m;
1013 if (model.userType() == qMetaTypeId<QJSValue>())
1015
1016 if (d->model == model)
1017 return;
1018
1019 if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(d->model)) {
1022 }
1023 if (QAbstractItemModel* aim = qvariant_cast<QAbstractItemModel *>(model)) {
1026 }
1027
1028 d->model = model;
1029 d->createDelegateModel();
1031 if (isComponentComplete()) {
1032 setCurrentIndex(count() > 0 ? 0 : -1);
1033 d->updateCurrentTextAndValue();
1034 }
1036
1037 d->maybeUpdateImplicitContentWidth();
1038}
1039
1047{
1048 Q_D(const QQuickComboBox);
1049 return d->delegateModel;
1050}
1051
1052
1063{
1064 Q_D(const QQuickComboBox);
1065 return d->pressed;
1066}
1067
1069{
1070 Q_D(QQuickComboBox);
1071 if (d->pressed == pressed)
1072 return;
1073
1074 d->pressed = pressed;
1076
1077 if (!d->hasDown) {
1078 setDown(d->pressed || d->isPopupVisible());
1079 d->hasDown = false;
1080 }
1081}
1082
1096{
1097 Q_D(const QQuickComboBox);
1098 return d->highlightedIndex;
1099}
1100
1111{
1112 Q_D(const QQuickComboBox);
1113 return d->currentIndex;
1114}
1115
1117{
1118 Q_D(QQuickComboBox);
1119 d->hasCurrentIndex = true;
1120 d->setCurrentIndex(index, NoActivate);
1121}
1122
1132{
1133 Q_D(const QQuickComboBox);
1134 return d->currentText;
1135}
1136
1157{
1158 Q_D(const QQuickComboBox);
1159 return d->displayText;
1160}
1161
1163{
1164 Q_D(QQuickComboBox);
1165 d->hasDisplayText = true;
1166 if (d->displayText == text)
1167 return;
1168
1169 d->displayText = text;
1172}
1173
1175{
1176 Q_D(QQuickComboBox);
1177 if (!d->hasDisplayText)
1178 return;
1179
1180 d->hasDisplayText = false;
1181 d->updateCurrentText();
1182}
1183
1184
1196{
1197 Q_D(const QQuickComboBox);
1198 return d->textRole;
1199}
1200
1202{
1203 Q_D(QQuickComboBox);
1204 if (d->textRole == role)
1205 return;
1206
1207 d->textRole = role;
1208 if (isComponentComplete())
1209 d->updateCurrentText();
1211}
1212
1225{
1226 Q_D(const QQuickComboBox);
1227 return d->valueRole;
1228}
1229
1231{
1232 Q_D(QQuickComboBox);
1233 if (d->valueRole == role)
1234 return;
1235
1236 d->valueRole = role;
1237 if (isComponentComplete())
1238 d->updateCurrentValue();
1239 emit valueRoleChanged();
1240}
1241
1266{
1267 Q_D(const QQuickComboBox);
1268 return d->delegate;
1269}
1270
1272{
1273 Q_D(QQuickComboBox);
1274 if (d->delegate == delegate)
1275 return;
1276
1277 delete d->delegate;
1278 d->delegate = delegate;
1279 QQmlDelegateModel *delegateModel = qobject_cast<QQmlDelegateModel*>(d->delegateModel);
1280 if (delegateModel)
1281 delegateModel->setDelegate(d->delegate);
1283}
1284
1293{
1294 QQuickComboBoxPrivate *d = const_cast<QQuickComboBoxPrivate *>(d_func());
1295 if (!d->indicator)
1296 d->executeIndicator();
1297 return d->indicator;
1298}
1299
1301{
1302 Q_D(QQuickComboBox);
1303 if (d->indicator == indicator)
1304 return;
1305
1307
1308 if (!d->indicator.isExecuting())
1309 d->cancelIndicator();
1310
1311 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
1312 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
1313
1314 d->removeImplicitSizeListener(d->indicator);
1316 d->indicator = indicator;
1317 if (indicator) {
1318 if (!indicator->parentItem())
1319 indicator->setParentItem(this);
1320 d->addImplicitSizeListener(indicator);
1321 }
1322
1323 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
1324 emit implicitIndicatorWidthChanged();
1325 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
1326 emit implicitIndicatorHeightChanged();
1327 if (!d->indicator.isExecuting())
1329}
1330
1345{
1346 QQuickComboBoxPrivate *d = const_cast<QQuickComboBoxPrivate *>(d_func());
1347 if (!d->popup)
1348 d->executePopup(isComponentComplete());
1349 return d->popup;
1350}
1351
1353{
1354 Q_D(QQuickComboBox);
1355 if (d->popup == popup)
1356 return;
1357
1358 if (!d->popup.isExecuting())
1359 d->cancelPopup();
1360
1361 if (d->popup) {
1365 }
1366 if (popup) {
1367 QQuickPopupPrivate::get(popup)->allowVerticalFlip = true;
1368 popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
1370 // QQuickPopup does not derive from QQuickItemChangeListener, so we cannot use
1371 // QQuickItemChangeListener::itemDestroyed so we have to use QObject::destroyed
1373
1374#if QT_CONFIG(quick_itemview)
1375 if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>())
1376 itemView->setHighlightRangeMode(QQuickItemView::NoHighlightRange);
1377#endif
1378 }
1379 d->popup = popup;
1380 if (!d->popup.isExecuting())
1382}
1383
1399{
1400 Q_D(const QQuickComboBox);
1401 return d->flat;
1402}
1403
1405{
1406 Q_D(QQuickComboBox);
1407 if (d->flat == flat)
1408 return;
1409
1410 d->flat = flat;
1411 emit flatChanged();
1412}
1413
1427{
1428 Q_D(const QQuickComboBox);
1429 return d->down;
1430}
1431
1433{
1434 Q_D(QQuickComboBox);
1435 d->hasDown = true;
1436
1437 if (d->down == down)
1438 return;
1439
1440 d->down = down;
1441 emit downChanged();
1442}
1443
1445{
1446 Q_D(QQuickComboBox);
1447 if (!d->hasDown)
1448 return;
1449
1450 setDown(d->pressed || d->isPopupVisible());
1451 d->hasDown = false;
1452}
1453
1465{
1466 Q_D(const QQuickComboBox);
1467 return d->extra.isAllocated() && d->extra->editable;
1468}
1469
1471{
1472 Q_D(QQuickComboBox);
1473 if (editable == isEditable())
1474 return;
1475
1476 if (d->contentItem) {
1477 if (editable) {
1478 d->contentItem->installEventFilter(this);
1479 if (QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem)) {
1482 }
1483#if QT_CONFIG(cursor)
1484 d->contentItem->setCursor(Qt::IBeamCursor);
1485#endif
1486 } else {
1487 d->contentItem->removeEventFilter(this);
1488 if (QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem)) {
1491 }
1492#if QT_CONFIG(cursor)
1493 d->contentItem->unsetCursor();
1494#endif
1495 }
1496 }
1497
1498 d->extra.value().editable = editable;
1499 setAccessibleProperty("editable", editable);
1500 emit editableChanged();
1501}
1502
1512{
1513 Q_D(const QQuickComboBox);
1514 return d->extra.isAllocated() ? d->extra->editText : QString();
1515}
1516
1518{
1519 Q_D(QQuickComboBox);
1520 if (text == editText())
1521 return;
1522
1523 d->extra.value().editText = text;
1524 emit editTextChanged();
1525}
1526
1531
1532#if QT_CONFIG(validator)
1562QValidator *QQuickComboBox::validator() const
1563{
1564 Q_D(const QQuickComboBox);
1565 return d->extra.isAllocated() ? d->extra->validator : nullptr;
1566}
1567
1568void QQuickComboBox::setValidator(QValidator *validator)
1569{
1570 Q_D(QQuickComboBox);
1571 if (validator == QQuickComboBox::validator())
1572 return;
1573
1574 d->extra.value().validator = validator;
1575#if QT_CONFIG(validator)
1576 if (validator)
1577 validator->setLocale(d->locale);
1578#endif
1579 emit validatorChanged();
1580}
1581#endif
1582
1594Qt::InputMethodHints QQuickComboBox::inputMethodHints() const
1595{
1596 Q_D(const QQuickComboBox);
1597 return d->extra.isAllocated() ? d->extra->inputMethodHints : Qt::ImhNoPredictiveText;
1598}
1599
1600void QQuickComboBox::setInputMethodHints(Qt::InputMethodHints hints)
1601{
1602 Q_D(QQuickComboBox);
1603 d->setInputMethodHints(hints);
1604}
1605
1618{
1619 Q_D(const QQuickComboBox);
1620 return d->contentItem && d->contentItem->property("inputMethodComposing").toBool();
1621}
1622
1636{
1637 Q_D(const QQuickComboBox);
1638 return d->m_acceptableInput;
1639}
1640
1656{
1657 Q_D(const QQuickComboBox);
1658 if (!d->indicator)
1659 return 0;
1660 return d->indicator->implicitWidth();
1661}
1662
1678{
1679 Q_D(const QQuickComboBox);
1680 if (!d->indicator)
1681 return 0;
1682 return d->indicator->implicitHeight();
1683}
1684
1697{
1698 Q_D(const QQuickComboBox);
1699 return d->currentValue;
1700}
1701
1711QVariant QQuickComboBox::valueAt(int index) const
1712{
1713 Q_D(const QQuickComboBox);
1714 if (!d->isValidIndex(index))
1715 return QVariant();
1716
1717 const QString effectiveValueRole = d->valueRole.isEmpty() ? QStringLiteral("modelData") : d->valueRole;
1718 return d->delegateModel->variantValue(index, effectiveValueRole);
1719}
1720
1733int QQuickComboBox::indexOfValue(const QVariant &value) const
1734{
1735 for (int i = 0; i < count(); ++i) {
1736 const QVariant ourValue = valueAt(i);
1737 if (value == ourValue)
1738 return i;
1739 }
1740 return -1;
1741}
1742
1753{
1754 Q_D(const QQuickComboBox);
1755 return d->extra.isAllocated() ? d->extra->selectTextByMouse : false;
1756}
1757
1759{
1760 Q_D(QQuickComboBox);
1761 if (canSelect == selectTextByMouse())
1762 return;
1763
1764 d->extra.value().selectTextByMouse = canSelect;
1765 emit selectTextByMouseChanged();
1766}
1767
1823{
1824 Q_D(const QQuickComboBox);
1825 return d->implicitContentWidthPolicy;
1826}
1827
1829{
1830 Q_D(QQuickComboBox);
1831 if (policy == d->implicitContentWidthPolicy)
1832 return;
1833
1834 d->implicitContentWidthPolicy = policy;
1835 d->maybeUpdateImplicitContentWidth();
1836 emit implicitContentWidthPolicyChanged();
1837}
1851{
1852 Q_D(const QQuickComboBox);
1853 if (!d->isValidIndex(index))
1854 return QString();
1855
1856 return d->delegateModel->stringValue(index, d->effectiveTextRole());
1857}
1858
1883int QQuickComboBox::find(const QString &text, Qt::MatchFlags flags) const
1884{
1885 Q_D(const QQuickComboBox);
1886 return d->match(0, text, flags);
1887}
1888
1898{
1899 Q_D(QQuickComboBox);
1900 d->incrementCurrentIndex();
1901}
1902
1912{
1913 Q_D(QQuickComboBox);
1914 d->decrementCurrentIndex();
1915}
1916
1925void QQuickComboBox::selectAll()
1926{
1927 Q_D(QQuickComboBox);
1928 QQuickTextInput *input = qobject_cast<QQuickTextInput *>(d->contentItem);
1929 if (!input)
1930 return;
1931 input->selectAll();
1932}
1933
1935{
1936 Q_D(QQuickComboBox);
1937 switch (event->type()) {
1939 if (d->isPopupVisible())
1940 d->hidePopup(false);
1941 break;
1942 case QEvent::KeyPress: {
1943 QKeyEvent *ke = static_cast<QKeyEvent *>(event);
1944 if (d->filterKeyEvent(ke, false))
1945 return true;
1946 event->accept();
1947 if (d->extra.isAllocated())
1948 d->extra->allowComplete = ke->key() != Qt::Key_Backspace && ke->key() != Qt::Key_Delete;
1949 break;
1950 }
1951 case QEvent::FocusOut:
1952 if (qGuiApp->focusObject() != this && (!d->popup || !d->popup->hasActiveFocus())) {
1953 // Only close the popup if focus was transferred somewhere else
1954 // than to the popup or the popup button (which normally means that
1955 // the user clicked on the popup button to open it, not close it).
1956 d->hidePopup(false);
1957 setPressed(false);
1958
1959 // The focus left the text field, so if the edit text matches an item in the model,
1960 // change our currentIndex to that. This matches widgets' behavior.
1961 const int indexForEditText = find(d->extra.value().editText, Qt::MatchFixedString);
1962 if (indexForEditText > -1)
1963 setCurrentIndex(indexForEditText);
1964 }
1965 break;
1966#if QT_CONFIG(im)
1968 if (d->extra.isAllocated())
1969 d->extra->allowComplete = !static_cast<QInputMethodEvent*>(event)->commitString().isEmpty();
1970 break;
1971#endif
1972 default:
1973 break;
1974 }
1975 return QQuickControl::eventFilter(object, event);
1976}
1977
1979{
1980 Q_D(QQuickComboBox);
1982 // Setting focus on TextField should not be done when drop down indicator was clicked
1983 // That is why, if focus is not set with key reason, it should not be passed to textEdit by default.
1984 // Focus on Edit Text should be set only intentionally by user.
1985 if ((event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ||
1986 event->reason() == Qt::ShortcutFocusReason) && d->contentItem && isEditable())
1987 d->contentItem->forceActiveFocus(event->reason());
1988}
1989
1991{
1992 Q_D(QQuickComboBox);
1994
1995 if (qGuiApp->focusObject() != d->contentItem && (!d->popup || !d->popup->hasActiveFocus())) {
1996 // Only close the popup if focus was transferred
1997 // somewhere else than to the popup or the inner line edit (which is
1998 // normally done from QQuickComboBox::focusInEvent).
1999 d->hidePopup(false);
2000 setPressed(false);
2001 }
2002}
2003
2004#if QT_CONFIG(im)
2005void QQuickComboBox::inputMethodEvent(QInputMethodEvent *event)
2006{
2007 Q_D(QQuickComboBox);
2008 QQuickControl::inputMethodEvent(event);
2009 if (!isEditable() && !event->commitString().isEmpty())
2010 d->keySearch(event->commitString());
2011 else
2012 event->ignore();
2013}
2014#endif
2015
2017{
2018 Q_D(QQuickComboBox);
2020
2021 const auto key = event->key();
2022 if (!isEditable()) {
2023 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>();
2024 if (buttonPressKeys.contains(key)) {
2025 if (!event->isAutoRepeat())
2026 setPressed(true);
2027 event->accept();
2028 return;
2029 }
2030 }
2031
2032 switch (key) {
2033 case Qt::Key_Escape:
2034 case Qt::Key_Back:
2035 if (d->isPopupVisible())
2036 event->accept();
2037 break;
2038 case Qt::Key_Enter:
2039 case Qt::Key_Return:
2040 if (d->isPopupVisible())
2041 setPressed(true);
2042 event->accept();
2043 break;
2044 case Qt::Key_Up:
2045 d->keyNavigating = true;
2046 d->decrementCurrentIndex();
2047 event->accept();
2048 break;
2049 case Qt::Key_Down:
2050 d->keyNavigating = true;
2051 d->incrementCurrentIndex();
2052 event->accept();
2053 break;
2054 case Qt::Key_Home:
2055 d->keyNavigating = true;
2056 if (d->isPopupVisible())
2057 d->setHighlightedIndex(0, Highlight);
2058 else
2059 d->setCurrentIndex(0, Activate);
2060 event->accept();
2061 break;
2062 case Qt::Key_End:
2063 d->keyNavigating = true;
2064 if (d->isPopupVisible())
2065 d->setHighlightedIndex(count() - 1, Highlight);
2066 else
2067 d->setCurrentIndex(count() - 1, Activate);
2068 event->accept();
2069 break;
2070 default:
2071 if (!isEditable() && !event->text().isEmpty())
2072 d->keySearch(event->text());
2073 else
2074 event->ignore();
2075 break;
2076 }
2077}
2078
2080{
2081 Q_D(QQuickComboBox);
2083 d->keyNavigating = false;
2084 if (event->isAutoRepeat())
2085 return;
2086
2087 const auto key = event->key();
2088 if (!isEditable()) {
2089 const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>();
2090 if (buttonPressKeys.contains(key)) {
2091 if (!isEditable() && isPressed())
2092 d->togglePopup(true);
2093 setPressed(false);
2094 event->accept();
2095 return;
2096 }
2097 }
2098
2099 switch (key) {
2100 case Qt::Key_Enter:
2101 case Qt::Key_Return:
2102 if (!isEditable() || d->isPopupVisible())
2103 d->hidePopup(d->isPopupVisible());
2104 setPressed(false);
2105 event->accept();
2106 break;
2107 case Qt::Key_Escape:
2108 case Qt::Key_Back:
2109 if (d->isPopupVisible()) {
2110 d->hidePopup(false);
2111 setPressed(false);
2112 event->accept();
2113 }
2114 break;
2115 default:
2116 break;
2117 }
2118}
2119
2120#if QT_CONFIG(wheelevent)
2121void QQuickComboBox::wheelEvent(QWheelEvent *event)
2122{
2123 Q_D(QQuickComboBox);
2124 QQuickControl::wheelEvent(event);
2125 if (d->wheelEnabled && !d->isPopupVisible()) {
2126 if (event->angleDelta().y() > 0)
2127 d->decrementCurrentIndex();
2128 else
2129 d->incrementCurrentIndex();
2130 }
2131}
2132#endif
2133
2135{
2136 Q_D(QQuickComboBox);
2137 if (e->type() == QEvent::LanguageChange)
2138 d->updateCurrentTextAndValue();
2139 return QQuickControl::event(e);
2140}
2141
2143{
2144 Q_D(QQuickComboBox);
2145 d->executeIndicator(true);
2147 if (d->popup)
2148 d->executePopup(true);
2149
2150 if (d->delegateModel && d->ownModel)
2151 static_cast<QQmlDelegateModel *>(d->delegateModel)->componentComplete();
2152
2153 if (count() > 0) {
2154 if (!d->hasCurrentIndex && d->currentIndex == -1)
2155 setCurrentIndex(0);
2156 else
2157 d->updateCurrentTextAndValue();
2158
2159 // If the widest text was already calculated in the call to
2160 // QQmlDelegateModel::componentComplete() above, then we shouldn't do it here too.
2161 if (!d->hasCalculatedWidestText)
2162 d->maybeUpdateImplicitContentWidth();
2163 }
2164}
2165
2167{
2168 Q_D(QQuickComboBox);
2170 if (change == ItemVisibleHasChanged && !value.boolValue) {
2171 d->hidePopup(false);
2172 setPressed(false);
2173 }
2174}
2175
2176void QQuickComboBox::fontChange(const QFont &newFont, const QFont &oldFont)
2177{
2178 Q_D(QQuickComboBox);
2179 QQuickControl::fontChange(newFont, oldFont);
2180 d->maybeUpdateImplicitContentWidth();
2181}
2182
2184{
2185 Q_D(QQuickComboBox);
2186 if (oldItem) {
2187 oldItem->removeEventFilter(this);
2188 if (QQuickTextInput *oldInput = qobject_cast<QQuickTextInput *>(oldItem)) {
2191 disconnect(oldInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickComboBox::inputMethodComposingChanged);
2193 }
2194 }
2195 if (newItem && isEditable()) {
2196 newItem->installEventFilter(this);
2197 if (QQuickTextInput *newInput = qobject_cast<QQuickTextInput *>(newItem)) {
2200 connect(newInput, &QQuickTextInput::inputMethodComposingChanged, this, &QQuickComboBox::inputMethodComposingChanged);
2202 }
2203#if QT_CONFIG(cursor)
2204 newItem->setCursor(Qt::IBeamCursor);
2205#endif
2206 }
2207
2208 d->updateAcceptableInput();
2209}
2210
2211void QQuickComboBox::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
2212{
2213 QQuickControl::localeChange(newLocale, oldLocale);
2214#if QT_CONFIG(validator)
2215 if (QValidator *v = validator())
2216 v->setLocale(newLocale);
2217#endif
2218}
2219
2224
2225#if QT_CONFIG(accessibility)
2226QAccessible::Role QQuickComboBox::accessibleRole() const
2227{
2228 return QAccessible::ComboBox;
2229}
2230
2231void QQuickComboBox::accessibilityActiveChanged(bool active)
2232{
2233 Q_D(QQuickComboBox);
2234 QQuickControl::accessibilityActiveChanged(active);
2235
2236 if (active) {
2237 maybeSetAccessibleName(d->hasDisplayText ? d->displayText : d->currentText);
2238 setAccessibleProperty("editable", isEditable());
2239 }
2240}
2241#endif //
2242
2244
2245#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
Type type() const
Returns the event type.
Definition qcoreevent.h:304
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
Definition qfont.h:22
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:625
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:424
static constexpr Policy Preferred
static constexpr Policy Fixed
T value(qsizetype i) const
Definition qlist.h:664
T & first()
Definition qmap.h:419
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
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:328
\inmodule QtCore
Definition qobject.h:103
T findChild(QAnyStringView aName, 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:155
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 event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
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
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QQmlComponent class encapsulates a QML component definition.
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
void itemDestroyed(QQuickItem *item) 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)
void itemDestroyed(QQuickItem *item) override
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 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:63
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:144
@ ItemVisibleHasChanged
Definition qquickitem.h:148
void setFocusPolicy(Qt::FocusPolicy policy)
Sets the focus policy of this item to policy.
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()
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:129
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:5455
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4833
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:65
T value() const &
Definition qvariant.h:516
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:714
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has userType() \l QMetaType::QVariantList.
int userType() const
Definition qvariant.h:339
QMetaType metaType() const
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7822
bool isEnabled() const
Definition qwidget.h:814
QString text
QPushButton * button
[2]
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
@ NoFocus
Definition qnamespace.h:107
@ StrongFocus
Definition qnamespace.h:110
@ ArrowCursor
@ IBeamCursor
@ ImhNone
@ ImhNoPredictiveText
@ Key_Escape
Definition qnamespace.h:663
@ Key_Return
Definition qnamespace.h:667
@ Key_Enter
Definition qnamespace.h:668
@ Key_Backspace
Definition qnamespace.h:666
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ Key_Delete
Definition qnamespace.h:670
@ Key_Back
Definition qnamespace.h:846
@ Key_Home
Definition qnamespace.h:675
@ Key_End
Definition qnamespace.h:676
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:333
#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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
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:75
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:492
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:35
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
myObject disconnect()
[26]
p rx()++
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
QSizePolicy policy
Qt::InputMethodHints inputMethodHints
\inmodule QtQuick
Definition qquickitem.h:159