diff options
author | Bartlomiej Moskal <bartlomiej.moskal@qt.io> | 2021-01-21 09:52:45 +0100 |
---|---|---|
committer | Bartlomiej Moskal <bartlomiej.moskal@qt.io> | 2021-02-16 14:59:57 +0100 |
commit | fdece5a40729d7c370d920ddfcad2921183dbbec (patch) | |
tree | 7be82bc2e70d15d0f51c7caec6ca784cd72a9d30 | |
parent | 367edbfbc3a29827f9c34800b4de509c8629e38a (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
Pick-to: 5.15 6.0
Change-Id: I813dcc3099c919ec32f0683e7e60e6082c5bc389
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickcombobox.cpp | 6 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 31 |
2 files changed, 30 insertions, 7 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index c01d6394..c12ea962 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 835a7b8d..460c490a 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -1547,7 +1547,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) @@ -1584,7 +1584,7 @@ TestCase { compare(control.currentIndex, 0) compare(control.currentText, "first") - control.forceActiveFocus() + control.contentItem.forceActiveFocus() compare(control.activeFocus, true) control.selectAll() @@ -1607,7 +1607,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 @@ -1758,7 +1758,7 @@ TestCase { var control = createTemporaryObject(keysAttachedBox, testCase) verify(control) - control.forceActiveFocus() + control.contentItem.forceActiveFocus() verify(control.activeFocus) verify(!control.gotit) @@ -2013,7 +2013,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") @@ -2031,7 +2031,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") @@ -2221,4 +2221,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) + } } |