aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcombobox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickcombobox.cpp')
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index a7450d76..278f8608 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -170,6 +170,7 @@ public:
void updateCurrentText();
void incrementCurrentIndex();
void decrementCurrentIndex();
+ void updateHighlightedIndex();
void setHighlightedIndex(int index);
void createDelegateModel();
@@ -200,19 +201,17 @@ void QQuickComboBoxPrivate::showPopup()
{
if (popup && !popup->isVisible())
popup->open();
- setHighlightedIndex(currentIndex);
}
void QQuickComboBoxPrivate::hidePopup(bool accept)
{
Q_Q(QQuickComboBox);
- if (popup && popup->isVisible())
- popup->close();
if (accept) {
q->setCurrentIndex(highlightedIndex);
emit q->activated(currentIndex);
}
- setHighlightedIndex(-1);
+ if (popup && popup->isVisible())
+ popup->close();
}
void QQuickComboBoxPrivate::togglePopup(bool accept)
@@ -303,6 +302,11 @@ void QQuickComboBoxPrivate::decrementCurrentIndex()
}
}
+void QQuickComboBoxPrivate::updateHighlightedIndex()
+{
+ setHighlightedIndex(popup->isVisible() ? currentIndex : -1);
+}
+
void QQuickComboBoxPrivate::setHighlightedIndex(int index)
{
Q_Q(QQuickComboBox);
@@ -655,10 +659,13 @@ void QQuickComboBox::setPopup(QQuickPopup *popup)
if (d->popup == popup)
return;
+ if (d->popup)
+ QObjectPrivate::disconnect(d->popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::updateHighlightedIndex);
d->deleteDelegate(d->popup);
if (popup) {
QQuickPopupPrivate::get(popup)->allowVerticalFlip = true;
popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
+ QObjectPrivate::connect(popup, &QQuickPopup::visibleChanged, d, &QQuickComboBoxPrivate::updateHighlightedIndex);
}
d->popup = popup;
emit popupChanged();