diff options
author | Santtu Lakkala <santtu.lakkala@nomovok.com> | 2015-06-16 12:03:38 +0300 |
---|---|---|
committer | Santtu Lakkala <santtu.lakkala@nomovok.com> | 2015-06-23 12:39:02 +0000 |
commit | 686f6a71fe5ac842c38ee74c690bd659c89fa393 (patch) | |
tree | 271c224a67bab49516536c19860cfbe9555adfe1 | |
parent | 234dc90be6850135b3b54c98fabe71eff1c6071c (diff) | |
download | qtquickcontrols-686f6a71fe5ac842c38ee74c690bd659c89fa393.tar.gz qtquickcontrols-686f6a71fe5ac842c38ee74c690bd659c89fa393.tar.bz2 qtquickcontrols-686f6a71fe5ac842c38ee74c690bd659c89fa393.zip |
ComboBox: Update selected text with item text
Bind the text of a inactive ComboBox to the text of the selected popup menu
item, so that the text updates when the model changes.
Task-number: QTBUG-46611
Change-Id: Ieba4d8ee7d9b37390e805a3bde58bf546c5009b1
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
-rw-r--r-- | src/controls/ComboBox.qml | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index 509a4b3d..3463470f 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -642,7 +642,7 @@ Control { var selectedItem; if (__selectedIndex !== -1 && (selectedItem = items[__selectedIndex])) { input.editTextMatches = true - selectedText = selectedItem.text + selectedText = Qt.binding(function () { return selectedItem.text }) if (currentText !== selectedText) // __selectedIndex went form -1 to 0 selectedTextChanged() } diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index b6eaaf6d..af1fc9dd 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -743,5 +743,16 @@ TestCase { test.destroy() } + + function test_modelDataChange() { + var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.2 ; ComboBox {}', testCase, ''); + comboBox.textRole = "text" + comboBox.model = model + compare(comboBox.currentIndex, 0) + compare(comboBox.currentText, "Banana") + model.set(0, { text: "Pomegranate", color: "Yellow" }) + compare(comboBox.currentText, "Pomegranate") + comboBox.destroy() + } } } |