From 95e720471ad28cae66b24e7809897f148311599f Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 22 Jul 2021 09:56:04 +0200 Subject: Pass the focus reason through to the control on mouse press Otherwise, a TextInput item will always receive OtherFocusReason when clicking into it. Add a test that simulates focus changes with mouse and keys, records the incoming focus events and verifies the correct focus reason is set in the event. Qt Quick provides no mechanism to access the focus reason from within QML (onActiveFocusChange only has a bool parameter, the focusReason property exists only in QtQuickControl). Task-number: QTBUG-75862 Change-Id: Ifea95c7ef2ac88c6c8e8bbdc8d2dbe5205ff922e Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale (cherry picked from commit bbcbb7c78f2f07e6c5e380ec5c018ac2a7abf292) Reviewed-by: Qt Cherry-pick Bot --- .../quick/qquicktextinput/data/focusReason.qml | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/auto/quick/qquicktextinput/data/focusReason.qml (limited to 'tests/auto/quick/qquicktextinput/data/focusReason.qml') diff --git a/tests/auto/quick/qquicktextinput/data/focusReason.qml b/tests/auto/quick/qquicktextinput/data/focusReason.qml new file mode 100644 index 0000000000..7ac913d363 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/focusReason.qml @@ -0,0 +1,39 @@ +import QtQuick 2.2 + +Rectangle { + width: 400 + height: 400 + + Column { + spacing: 5 + TextInput { + id: first + objectName: "first" + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + KeyNavigation.backtab: third + KeyNavigation.tab: second + KeyNavigation.down: second + } + TextInput { + id: second + objectName: "second" + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + KeyNavigation.up: first + KeyNavigation.backtab: first + KeyNavigation.tab: third + } + TextInput { + objectName: "third" + id: third + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + KeyNavigation.backtab: second + KeyNavigation.tab: first + } + Component.onCompleted: { + first.focus = true + } + } +} -- cgit v1.2.3