aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-12-06 13:13:51 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-12-10 12:40:32 +0100
commitcb1c3528078659c297fb12ea6914978cec1d2614 (patch)
tree0327c155724c25e331b08d835360c191f64c55f9 /tests
parentaaec25a798352fc222f86ab3b299384575f51dc8 (diff)
ComboBox: change currentIndex (if applicable) when focus is lost
When the user enters text into an editable ComboBox that matches the text of an entry in the model, and then tabs out to another item, the currentIndex should be changed to that entry. This brings the behavior of ComboBox in line with QComboBox. Change-Id: Ibb1e201a503704681ebcbc7135d1964cc1f6bbca Fixes: QTBUG-78885 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 2cf71f73..634d70a8 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -1853,4 +1853,56 @@ TestCase {
closedSpy.wait()
compare(closedSpy.count, 1)
}
+
+ // QTBUG-78885: When the edit text is changed on an editable ComboBox,
+ // and then that ComboBox loses focus, its currentIndex should change
+ // to the index of the edit text (assuming a match is found).
+ function test_currentIndexChangeOnLostFocus() {
+ if (Qt.styleHints.tabFocusBehavior !== Qt.TabFocusAllControls)
+ skip("This platform only allows tab focus for text controls")
+
+ let theModel = []
+ for (let i = 0; i < 10; ++i)
+ theModel.push("Item " + (i + 1))
+
+ let comboBox1 = createTemporaryObject(comboBox, testCase,
+ { objectName: "comboBox1", editable: true, model: theModel })
+ verify(comboBox1)
+ compare(comboBox1.currentIndex, 0)
+
+ let comboBox2 = createTemporaryObject(comboBox, testCase, { objectName: "comboBox2" })
+ verify(comboBox2)
+
+ // Give the first ComboBox focus and type in 0 to select "Item 10" (default is "Item 1").
+ waitForRendering(comboBox1)
+ comboBox1.forceActiveFocus()
+ verify(comboBox1.activeFocus)
+ keyClick(Qt.Key_0)
+ compare(comboBox1.editText, "Item 10")
+
+ let currentIndexSpy = signalSpy.createObject(comboBox1,
+ { target: comboBox1, signalName: "currentIndexChanged" })
+ verify(currentIndexSpy.valid)
+
+ // Give focus to the other ComboBox so that the first one loses it.
+ // The first ComboBox's currentIndex should change to that of "Item 10".
+ keyClick(Qt.Key_Tab)
+ verify(comboBox2.activeFocus)
+ compare(comboBox1.currentIndex, 9)
+ compare(currentIndexSpy.count, 1)
+
+ // Give focus back to the first ComboBox, and try the same thing except
+ // with non-existing text; the currentIndex should not change.
+ comboBox1.forceActiveFocus()
+ verify(comboBox1.activeFocus)
+ keySequence(StandardKey.SelectAll)
+ compare(comboBox1.contentItem.selectedText, "Item 10")
+ keyClick(Qt.Key_N)
+ keyClick(Qt.Key_O)
+ keyClick(Qt.Key_P)
+ keyClick(Qt.Key_E)
+ compare(comboBox1.editText, "nope")
+ compare(comboBox1.currentIndex, 9)
+ compare(currentIndexSpy.count, 1)
+ }
}