aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartlomiej Moskal <bartlomiej.moskal@qt.io>2021-01-21 09:52:45 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-16 14:58:34 +0000
commit46dd9419b0e2f5fcaf887cad6289a0fc7b6d0385 (patch)
tree7262fa8cb1a5c28cfd66656a8f3130d2e7242e84
parent6db222f0d455f8062587c51c8936d8de82e001ab (diff)
ComboBox: don't focus TextField when clicking on indicator
Remove focusing editText for Combobox when clicking on indicator (when editable is set to true). Focus on Edit Text should be set only intentionally by user. Before this change, when focus was set on Combobox, it automatically set focus on editText. It was also happening when drop down indicator was clicked. Because of that, on some platform (like Android) virtual keyboard was appearing in case when it shouldn't be shown. Fixes: QTBUG-61021 Change-Id: I813dcc3099c919ec32f0683e7e60e6082c5bc389 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit fdece5a40729d7c370d920ddfcad2921183dbbec) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp6
-rw-r--r--tests/auto/controls/data/tst_combobox.qml31
2 files changed, 30 insertions, 7 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 302a32f0..30f43e74 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -1905,7 +1905,11 @@ void QQuickComboBox::focusInEvent(QFocusEvent *event)
{
Q_D(QQuickComboBox);
QQuickControl::focusInEvent(event);
- if (d->contentItem && isEditable())
+ // Setting focus on TextField should not be done when drop down indicator was clicked
+ // That is why, if focus is not set with key reason, it should not be passed to textEdit by default.
+ // Focus on Edit Text should be set only intentionally by user.
+ if ((event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ||
+ event->reason() == Qt::ShortcutFocusReason) && d->contentItem && isEditable())
d->contentItem->forceActiveFocus(event->reason());
}
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 3faf9c9a..a78ed207 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -1497,7 +1497,7 @@ TestCase {
control.editText = ""
compare(control.acceptableInput, true)
control.editText = ""
- control.forceActiveFocus()
+ control.contentItem.forceActiveFocus()
keyPress(Qt.Key_A)
compare(control.editText, "")
keyPress(Qt.Key_A)
@@ -1534,7 +1534,7 @@ TestCase {
compare(control.currentIndex, 0)
compare(control.currentText, "first")
- control.forceActiveFocus()
+ control.contentItem.forceActiveFocus()
compare(control.activeFocus, true)
control.selectAll()
@@ -1557,7 +1557,7 @@ TestCase {
var control = createTemporaryObject(comboBox, testCase, {editable: true, model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]})
verify(control)
- control.forceActiveFocus()
+ control.contentItem.forceActiveFocus()
verify(control.activeFocus)
var acceptCount = 0
@@ -1708,7 +1708,7 @@ TestCase {
var control = createTemporaryObject(keysAttachedBox, testCase)
verify(control)
- control.forceActiveFocus()
+ control.contentItem.forceActiveFocus()
verify(control.activeFocus)
verify(!control.gotit)
@@ -1963,7 +1963,7 @@ TestCase {
// Give the first ComboBox focus and type in 0 to select "Item 10" (default is "Item 1").
waitForRendering(comboBox1)
- comboBox1.forceActiveFocus()
+ comboBox1.contentItem.forceActiveFocus()
verify(comboBox1.activeFocus)
keyClick(Qt.Key_0)
compare(comboBox1.editText, "Item 10")
@@ -1981,7 +1981,7 @@ TestCase {
// Give focus back to the first ComboBox, and try the same thing except
// with non-existing text; the currentIndex should not change.
- comboBox1.forceActiveFocus()
+ comboBox1.contentItem.forceActiveFocus()
verify(comboBox1.activeFocus)
keySequence(StandardKey.SelectAll)
compare(comboBox1.contentItem.selectedText, "Item 10")
@@ -2171,4 +2171,23 @@ TestCase {
control.font.pixelSize *= 2
compare(Math.ceil(control.implicitContentWidth), Math.ceil(oldTextFieldImplicitWidth))
}
+
+ // QTBUG-61021: text line should not be focused by default
+ // It causes (e.g. on Android) showing virtual keyboard when it is not needed
+ function test_doNotFocusTextLineByDefault() {
+ var control = createTemporaryObject(comboBox, testCase)
+ // Focus not set after creating combobox
+ verify(!control.activeFocus)
+ verify(!control.contentItem.focus)
+
+ // After setting focus on combobox, text line should not be focused
+ control.forceActiveFocus()
+ verify(control.activeFocus)
+ verify(!control.contentItem.focus)
+
+ // Text line is focused after intentional setting focus on it
+ control.contentItem.forceActiveFocus()
+ verify(control.activeFocus)
+ verify(control.contentItem.focus)
+ }
}