diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-10-01 23:02:43 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-10-02 12:49:15 +0000 |
commit | 4fb88d0f34e030223c75fc8903ef5d8325b649ed (patch) | |
tree | a691bdb06464050fce11ba8a5a9a04a4a91b5b64 /src/quicktemplates2/qquickcombobox.cpp | |
parent | bfaa08a335f21e6fdf533969779f806883fe27b0 (diff) |
Fix ComboBox to scroll to the highlighted item
Change-Id: I57fefd8ba47796118e71902c6882e9918d462920
Tasl-number: QTBUG-55030
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcombobox.cpp')
-rw-r--r-- | src/quicktemplates2/qquickcombobox.cpp | 15 |
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(); |