diff options
Diffstat (limited to 'src/quicktemplates/qquickcombobox.cpp')
-rw-r--r-- | src/quicktemplates/qquickcombobox.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/quicktemplates/qquickcombobox.cpp b/src/quicktemplates/qquickcombobox.cpp index 31eb97e31d..c55e988b74 100644 --- a/src/quicktemplates/qquickcombobox.cpp +++ b/src/quicktemplates/qquickcombobox.cpp @@ -23,7 +23,9 @@ #include <QtQuick/private/qquickevents_p_p.h> #include <QtQuick/private/qquicktextinput_p.h> #include <QtQuick/private/qquicktextinput_p_p.h> +#if QT_CONFIG(quick_itemview) #include <QtQuick/private/qquickitemview_p.h> +#endif QT_BEGIN_NAMESPACE @@ -209,6 +211,7 @@ public: void hidePopup(bool accept); void togglePopup(bool accept); void popupVisibleChanged(); + void popupDestroyed(); void itemClicked(); void itemHovered(); @@ -253,6 +256,7 @@ public: void itemImplicitWidthChanged(QQuickItem *item) override; void itemImplicitHeightChanged(QQuickItem *item) override; + void itemDestroyed(QQuickItem *item) override; void setInputMethodHints(Qt::InputMethodHints hints, bool force = false); @@ -342,14 +346,18 @@ void QQuickComboBoxPrivate::popupVisibleChanged() if (isPopupVisible()) QGuiApplication::inputMethod()->reset(); +#if QT_CONFIG(quick_itemview) QQuickItemView *itemView = popup->findChild<QQuickItemView *>(); if (itemView) itemView->setHighlightRangeMode(QQuickItemView::NoHighlightRange); +#endif updateHighlightedIndex(); +#if QT_CONFIG(quick_itemview) if (itemView) itemView->positionViewAtIndex(highlightedIndex, QQuickItemView::Beginning); +#endif if (!hasDown) { q->setDown(pressed || isPopupVisible()); @@ -357,6 +365,13 @@ void QQuickComboBoxPrivate::popupVisibleChanged() } } +void QQuickComboBoxPrivate::popupDestroyed() +{ + Q_Q(QQuickComboBox); + popup = nullptr; + emit q->popupChanged(); +} + void QQuickComboBoxPrivate::itemClicked() { Q_Q(QQuickComboBox); @@ -381,8 +396,10 @@ void QQuickComboBoxPrivate::itemHovered() if (index != -1) { setHighlightedIndex(index, Highlight); +#if QT_CONFIG(quick_itemview) if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>()) itemView->positionViewAtIndex(index, QQuickItemView::Contain); +#endif } } @@ -767,8 +784,6 @@ void QQuickComboBoxPrivate::handleUngrab() q->setPressed(false); } -static inline QString indicatorName() { return QStringLiteral("indicator"); } - void QQuickComboBoxPrivate::cancelIndicator() { Q_Q(QQuickComboBox); @@ -833,6 +848,16 @@ void QQuickComboBoxPrivate::itemImplicitHeightChanged(QQuickItem *item) emit q->implicitIndicatorHeightChanged(); } +void QQuickComboBoxPrivate::itemDestroyed(QQuickItem *item) +{ + Q_Q(QQuickComboBox); + QQuickControlPrivate::itemDestroyed(item); + if (item == indicator) { + indicator = nullptr; + emit q->indicatorChanged(); + } +} + qreal QQuickComboBoxPrivate::getContentWidth() const { if (componentComplete) { @@ -929,6 +954,7 @@ QQuickComboBox::QQuickComboBox(QQuickItem *parent) #endif Q_D(QQuickComboBox); d->setInputMethodHints(Qt::ImhNoPredictiveText, true); + d->setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed); } QQuickComboBox::~QQuickComboBox() @@ -1333,6 +1359,7 @@ void QQuickComboBox::setPopup(QQuickPopup *popup) d->cancelPopup(); if (d->popup) { + QObjectPrivate::disconnect(d->popup.data(), &QQuickPopup::destroyed, d, &QQuickComboBoxPrivate::popupDestroyed); QObjectPrivate::disconnect(d->popup.data(), &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::popupVisibleChanged); QQuickComboBoxPrivate::hideOldPopup(d->popup); } @@ -1340,9 +1367,14 @@ void QQuickComboBox::setPopup(QQuickPopup *popup) QQuickPopupPrivate::get(popup)->allowVerticalFlip = true; popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent); QObjectPrivate::connect(popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::popupVisibleChanged); + // QQuickPopup does not derive from QQuickItemChangeListener, so we cannot use + // QQuickItemChangeListener::itemDestroyed so we have to use QObject::destroyed + QObjectPrivate::connect(popup, &QQuickPopup::destroyed, d, &QQuickComboBoxPrivate::popupDestroyed); +#if QT_CONFIG(quick_itemview) if (QQuickItemView *itemView = popup->findChild<QQuickItemView *>()) itemView->setHighlightRangeMode(QQuickItemView::NoHighlightRange); +#endif } d->popup = popup; if (!d->popup.isExecuting()) @@ -2056,7 +2088,7 @@ void QQuickComboBox::keyReleaseEvent(QKeyEvent *event) if (!isEditable()) { const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>(); if (buttonPressKeys.contains(key)) { - if (!isEditable()) + if (!isEditable() && isPressed()) d->togglePopup(true); setPressed(false); event->accept(); |