summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Krupenko <krnekit@gmail.com>2015-10-22 18:44:20 +0300
committerNikita Krupenko <krnekit@gmail.com>2015-10-26 11:14:17 +0000
commitd3dbbe4781c4a7137ada0324e6ec5b14fed5c859 (patch)
tree2e4c18f5d36d33542ef1dc55ff5e53aa56a4cbd4
parent32d11f2d679b811c9af349fe9f0b0b29d4f598c0 (diff)
downloadqtquickcontrols-d3dbbe4781c4a7137ada0324e6ec5b14fed5c859.tar.gz
Allow ComboBox to select items with empty text
ComboBox checks selected text like a boolean value. This check is unnecessary and prevents from item with empty text could be selected. [ChangeLog][ComboBox] ComboBox is now able to select items with empty text. Task-number: QTBUG-42127 Change-Id: Ifaa0598d17c85cee099c88f4e03092137ba17c70 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/controls/ComboBox.qml2
-rw-r--r--tests/auto/controls/data/tst_combobox.qml19
2 files changed, 20 insertions, 1 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index a2eff0b6..8a2908b5 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -518,7 +518,7 @@ Control {
style: isPopup ? __style.__popupStyle : __style.__dropDownStyle
property string currentText: selectedText
- onSelectedTextChanged: if (selectedText) popup.currentText = selectedText
+ onSelectedTextChanged: popup.currentText = selectedText
property string selectedText
on__SelectedIndexChanged: {
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index da8c79f8..cecc3928 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -682,6 +682,25 @@ TestCase {
return index
}
+ function test_emptyTextItem() {
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.2 ; ComboBox { }', testCase, '');
+ comboBox.model = [
+ "1",
+ "",
+ "3"
+ ]
+ compare(comboBox.currentIndex, 0)
+ compare(comboBox.currentText, "1")
+ comboBox.currentIndex = 1
+ compare(comboBox.currentIndex, 1)
+ compare(comboBox.currentText, "")
+ comboBox.currentIndex = 2
+ compare(comboBox.currentIndex, 2)
+ compare(comboBox.currentText, "3")
+ compare(comboBox.find(""), 1)
+ comboBox.destroy()
+ }
+
function test_minusOneIndexResetsSelection_QTBUG_35794() {
var qmlObjects = ['import QtQuick.Controls 1.2 ; ComboBox { model: ["A", "B", "C"] }',
'import QtQuick.Controls 1.2 ; ComboBox { editable: true; model: ["A", "B", "C"] }']