diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2022-07-26 10:53:46 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-28 12:58:47 +0000 |
commit | 75090f2357054ebc16c018aa33457337a6237637 (patch) | |
tree | f00f4e31c5e9622f18568f15a24b1db23b13339c | |
parent | 4815700b7842d70a08647e0f5942032fb63f004f (diff) |
ScrollView: ignore filtered wheel events when wheelEnabled is false
The event filter was returning true when wheelEnabled was false,
but wasn't ignoring the event, meaning that propagation of the wheel
event stopped there, and items behind the ScrollView didn't get the
event even if ScrollView wasn't using it.
I'm not sure why it was done this way - the behavior isn't documented
and no auto tests fail when changing it.
Fixes: QTBUG-105164
Change-Id: Ie826ccfc406b77606ef0c6f043dc48f42a18cdc7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 7ef12715baf48912f713e6cb3ee2a784caaadaae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quicktemplates2/qquickscrollview.cpp | 4 | ||||
-rw-r--r-- | tests/auto/quickcontrols2/controls/data/tst_scrollview.qml | 46 |
2 files changed, 48 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickscrollview.cpp b/src/quicktemplates2/qquickscrollview.cpp index 956785402f..6e2660acd7 100644 --- a/src/quicktemplates2/qquickscrollview.cpp +++ b/src/quicktemplates2/qquickscrollview.cpp @@ -531,8 +531,10 @@ bool QQuickScrollView::eventFilter(QObject *object, QEvent *event) Q_D(QQuickScrollView); if (event->type() == QEvent::Wheel) { d->setScrollBarsInteractive(true); - if (!d->wheelEnabled) + if (!d->wheelEnabled) { + event->ignore(); return true; + } } return QQuickPane::eventFilter(object, event); } diff --git a/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml b/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml index 6e09c65e70..7b6614eea2 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml @@ -61,7 +61,7 @@ TestCase { name: "ScrollView" Component { - id: signalSpy + id: signalSpyComponent SignalSpy { } } @@ -581,4 +581,48 @@ TestCase { verify(newHorizontalScrollBar.visible) verify(!oldHorizontalScrollBar.visible) } + + Component { + id: mouseAreaWheelComponent + + MouseArea { + anchors.fill: parent + + property alias scrollView: scrollView + property alias flickable: flickable + + ScrollView { + id: scrollView + anchors.fill: parent + wheelEnabled: false + + Flickable { + id: flickable + contentHeight: 1000 + + Text { + text: "Test" + width: 500 + height: 1000 + } + } + } + } + } + + // If a ScrollView containing a Flickable sets wheelEnabled to false, + // neither item should consume wheel events. + function test_wheelEnabled() { + let mouseArea = createTemporaryObject(mouseAreaWheelComponent, testCase) + verify(mouseArea) + + let mouseWheelSpy = signalSpyComponent.createObject(mouseArea, + { target: mouseArea, signalName: "wheel" }) + verify(mouseWheelSpy.valid) + + let scrollView = mouseArea.scrollView + mouseWheel(scrollView, scrollView.width / 2, scrollView.height / 2, 0, 120) + compare(mouseWheelSpy.count, 1) + compare(mouseArea.flickable.contentY, 0) + } } |