From 19976fd5db1f2fb4925831c5f7a708c090e4a70e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 11 Nov 2019 13:44:22 +0100 Subject: SwipeView: fix issue where child items couldn't get focus Set the focus property of the contentItem (ListView) to the focus property of the SwipeView itself. Change-Id: Ic410f7fb8db9fbb758b956dfe07e1b4265f5f687 Fixes: QTBUG-62401 Reviewed-by: Richard Moe Gustavsen --- src/imports/controls/SwipeView.qml | 1 + src/imports/controls/imagine/SwipeView.qml | 1 + src/imports/controls/material/SwipeView.qml | 1 + tests/auto/controls/data/tst_swipeview.qml | 49 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/src/imports/controls/SwipeView.qml b/src/imports/controls/SwipeView.qml index ad242e1a..7722d258 100644 --- a/src/imports/controls/SwipeView.qml +++ b/src/imports/controls/SwipeView.qml @@ -50,6 +50,7 @@ T.SwipeView { model: control.contentModel interactive: control.interactive currentIndex: control.currentIndex + focus: control.focus spacing: control.spacing orientation: control.orientation diff --git a/src/imports/controls/imagine/SwipeView.qml b/src/imports/controls/imagine/SwipeView.qml index 4998edb7..70d65fef 100644 --- a/src/imports/controls/imagine/SwipeView.qml +++ b/src/imports/controls/imagine/SwipeView.qml @@ -61,6 +61,7 @@ T.SwipeView { model: control.contentModel interactive: control.interactive currentIndex: control.currentIndex + focus: control.focus spacing: control.spacing orientation: control.orientation diff --git a/src/imports/controls/material/SwipeView.qml b/src/imports/controls/material/SwipeView.qml index 12ea36ae..a84f16c5 100644 --- a/src/imports/controls/material/SwipeView.qml +++ b/src/imports/controls/material/SwipeView.qml @@ -50,6 +50,7 @@ T.SwipeView { model: control.contentModel interactive: control.interactive currentIndex: control.currentIndex + focus: control.focus spacing: control.spacing orientation: control.orientation diff --git a/tests/auto/controls/data/tst_swipeview.qml b/tests/auto/controls/data/tst_swipeview.qml index 38af37f7..5775491c 100644 --- a/tests/auto/controls/data/tst_swipeview.qml +++ b/tests/auto/controls/data/tst_swipeview.qml @@ -574,4 +574,53 @@ TestCase { compare(control.itemAt(i).x, 0) } } + + Component { + id: focusSwipeViewComponent + + SwipeView { + id: swipeView + anchors.fill: parent + focus: true + + property int pressCount + property int releaseCount + property int rectanglePressCount + property int rectangleReleaseCount + + Rectangle { + focus: true + + Keys.onPressed: ++swipeView.rectanglePressCount + Keys.onReleased: ++swipeView.rectangleReleaseCount + } + + Keys.onPressed: ++pressCount + Keys.onReleased: ++releaseCount + } + } + + function test_focus() { + if (Qt.styleHints.tabFocusBehavior !== Qt.TabFocusAllControls) + skip("This platform only allows tab focus for text controls") + + var control = createTemporaryObject(focusSwipeViewComponent, testCase) + verify(control) + compare(control.focus, true) + compare(control.contentItem.focus, true) + compare(control.itemAt(0).focus, true) + compare(control.itemAt(0).activeFocus, true) + + keyPress(Qt.Key_A) + compare(control.pressCount, 1) + compare(control.releaseCount, 0) + compare(control.rectanglePressCount, 1) + compare(control.rectangleReleaseCount, 0) + + keyRelease(Qt.Key_A) + compare(control.pressCount, 1) + compare(control.releaseCount, 1) + compare(control.rectanglePressCount, 1) + compare(control.rectangleReleaseCount, 1) + } } -- cgit v1.2.3