diff options
author | Alberto Mardegan <mardy@users.sourceforge.net> | 2016-02-15 00:04:14 +0300 |
---|---|---|
committer | Alberto Mardegan <mardy@users.sourceforge.net> | 2018-02-12 19:04:27 +0000 |
commit | 8889eaacc45b9a5e35e9c3182dece9f46560b2de (patch) | |
tree | f799afe28dccdb35fb929c14d32c6a3a899fe7e8 /src | |
parent | 4459886e3f949821425dd5fd9fc9da0416d0ffc9 (diff) | |
download | qtquickcontrols-8889eaacc45b9a5e35e9c3182dece9f46560b2de.tar.gz |
ComboBox: guarantee index consistency when emitting activated()
The "triggered" signal from the ComboBox menu items is handled twice:
once in ComboBox.qml, and once in QQuickMenuItem. The function of the
latter is to update the parent QQuickMenu's selected index.
With the current change we guarantee that the selected index (that is
exposed as "currentIndex" in the public API) is updated only once,
before any activated() signal is emitted. This also allows the handler
of the activated() signal to update currentIndex at will, without
running the risk of having it overwritten again by the ComboBox internal
code.
Task-number: QTBUG-51113
Task-number: QTBUG-43050
Change-Id: Ibfe12752d02eb4c9e2bf9a73ee8b3ab0ca8d7eaa
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/ComboBox.qml | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index bd42f76b..7c6f93a7 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -570,11 +570,16 @@ Control { onSelectedTextChanged: popup.currentText = selectedText property string selectedText + property int triggeredIndex: -1 on__SelectedIndexChanged: { if (__selectedIndex === -1) popup.currentText = "" else updateSelectedText() + if (triggeredIndex >= 0 && triggeredIndex == __selectedIndex) { + activated(currentIndex) + triggeredIndex = -1 + } } property string textRole: "" @@ -611,8 +616,7 @@ Control { modelData : ((popup.modelIsArray ? modelData[popup.textRole] : model[popup.textRole]) || '') onTriggered: { - if (index !== currentIndex) - activated(index) + popup.triggeredIndex = index comboBox.editText = text } onTextChanged: if (index === currentIndex) popup.updateSelectedText(); |