summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanttu Lakkala <santtu.lakkala@nomovok.com>2015-06-16 12:03:38 +0300
committerSanttu Lakkala <santtu.lakkala@nomovok.com>2015-06-23 12:39:02 +0000
commit686f6a71fe5ac842c38ee74c690bd659c89fa393 (patch)
tree271c224a67bab49516536c19860cfbe9555adfe1
parent234dc90be6850135b3b54c98fabe71eff1c6071c (diff)
downloadqtquickcontrols-686f6a71fe5ac842c38ee74c690bd659c89fa393.tar.gz
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.qml2
-rw-r--r--tests/auto/controls/data/tst_combobox.qml11
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()
+ }
}
}