diff options
author | Doris Verria <doris.verria@qt.io> | 2024-05-06 19:33:27 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2024-05-14 20:06:17 +0200 |
commit | 199b603633ee0827297a165cc2051a2f56b1eb8e (patch) | |
tree | ca832b03e28588d8a890ba33b5e628d76b36f15d /tests | |
parent | 757bfef221654d5aeee72086393bd67b2c8554e5 (diff) |
Force active focus to target item in setFocusToTargetItem
It is not enough to call setFocus on the target item, as there
may be other focus scopes currently holding the active focus.
Call forceActiveFocus instead.
Also, if the target item is the First or Last target, we want
to explicitly set the focus to the first/last item of the window
that can receive focus. If that item is a FocusScope we need to
clear its previous subFocusItem.
Task-number: QTBUG-121789
Change-Id: I99e5da5727dfd99c76bf2fc0baf7e9b8330f7c4d
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickitem2/data/embedded_FocusScope.qml | 37 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 11 |
2 files changed, 47 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickitem2/data/embedded_FocusScope.qml b/tests/auto/quick/qquickitem2/data/embedded_FocusScope.qml new file mode 100644 index 0000000000..0d154f76e5 --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/embedded_FocusScope.qml @@ -0,0 +1,37 @@ +import QtQuick + +Rectangle { + width: 300 + height: 300 + + FocusScope { + width: parent.width + height: parent.height + focus: true + + Column { + anchors.fill: parent + anchors.rightMargin: 2 + anchors.leftMargin: 2 + anchors.topMargin: 10 + spacing: 20 + Rectangle { + objectName: "rect1" + width: parent.width + height: 30 + border.width: 1 + border.color: activeFocus ? "blue" : "black" + focusPolicy: Qt.TabFocus + } + Rectangle { + objectName: "rect2" + width: parent.width + height: 30 + border.width: 1 + border.color: activeFocus ? "blue" : "black" + focusPolicy: Qt.TabFocus + focus: true + } + } + } +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 267be73ec9..56271ec3f2 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -140,6 +140,7 @@ private slots: void focusInScopeChanges(); #ifdef QT_WIDGETS_LIB + void embeddedInWidgetsFocus_data(); void embeddedInWidgetsFocus(); #endif @@ -4441,8 +4442,16 @@ void tst_QQuickItem::focusInScopeChanges() } #ifdef QT_WIDGETS_LIB +void tst_QQuickItem::embeddedInWidgetsFocus_data() +{ + QTest::addColumn<QUrl>("source"); + QTest::newRow("Embedded") << testFileUrl("embedded.qml"); + QTest::newRow("Embedded Focus Scope") << testFileUrl("embedded_FocusScope.qml"); +} + void tst_QQuickItem::embeddedInWidgetsFocus() { + QFETCH(QUrl, source); QWidget root; QVBoxLayout *layout = new QVBoxLayout(&root); @@ -4450,7 +4459,7 @@ void tst_QQuickItem::embeddedInWidgetsFocus() lineEdit1->setFocusPolicy(Qt::FocusPolicy::TabFocus); QQuickView *quickView = new QQuickView; - quickView->setSource(testFileUrl("embedded.qml")); + quickView->setSource(source); QWidget *container = QWidget::createWindowContainer(quickView, &root); container->setMinimumSize(quickView->size()); container->setFocusPolicy(Qt::TabFocus); |