diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-05-18 13:21:05 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-05-20 00:36:15 +0000 |
commit | 07e40cf567231d6ce30db120fa4ea17eb2bb323f (patch) | |
tree | 7c3d2e5905686390bf7817cf1f7c22e90c62afc9 | |
parent | 45df6f0bdc988890f34801677dab0a022e353c68 (diff) |
MouseArea: don't override preventStealing on mouse release
In setPreventStealing() we call setKeepMouseGrab(); so it does not make
sense to override setKeepMouseGrab() in other places without even
checking the state of the preventStealing property.
Fixes: QTBUG-103522
Change-Id: Ib4a2b01b814835715642aec83fac0a84debe2461
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit d92f1dfe05370c4a2ca7d86810e00b7466f454ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 3 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/data/preventStealingListViewChild.qml | 31 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 31 |
3 files changed, 64 insertions, 1 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 2b39ee987c..a8c747c4ef 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -808,7 +808,8 @@ void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event) QQuickWindow *w = window(); if (w && w->mouseGrabberItem() == this) ungrabMouse(); - setKeepMouseGrab(false); + if (!d->preventStealing) + setKeepMouseGrab(false); } } d->doubleClick = false; diff --git a/tests/auto/quick/qquickmousearea/data/preventStealingListViewChild.qml b/tests/auto/quick/qquickmousearea/data/preventStealingListViewChild.qml new file mode 100644 index 0000000000..3833c5a8a9 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/preventStealingListViewChild.qml @@ -0,0 +1,31 @@ +import QtQuick 2.15 + +ListView { + id: flick + width: 640 + height: 480 + model: 100 + + delegate: Rectangle { + border.color: "#81e889" + width: 640; height: 100 + Text { text: "Row " + index } + } + + Rectangle { + anchors.right: parent.right + anchors.margins: 2 + color: ma.pressed ? "#81e889" : "#c2f4c6" + width: 50; height: 50 + radius: 5 + MouseArea { + id: ma + anchors.fill: parent + preventStealing: true + drag { + target: parent + axis: Drag.YAxis + } + } + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 36f37e0b95..50cc536795 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -123,6 +123,7 @@ private slots: void invalidClick(); void pressedOrdering(); void preventStealing(); + void preventStealingListViewChild(); void clickThrough(); void hoverPosition(); void hoverPropagation(); @@ -1092,6 +1093,36 @@ void tst_QQuickMouseArea::preventStealing() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p); } +// QTBUG-103522 +void tst_QQuickMouseArea::preventStealingListViewChild() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("preventStealingListViewChild.qml"))); + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window.rootObject()); + QVERIFY(flickable); + QQuickMouseArea *mouseArea = flickable->findChild<QQuickMouseArea*>(); + QVERIFY(mouseArea); + QPoint p = mouseArea->mapToScene(mouseArea->boundingRect().center()).toPoint(); + const int threshold = qApp->styleHints()->startDragDistance(); + + flickable->flick(0, -10000); + for (int i = 0; i < 2; ++i) { + QVERIFY(flickable->isMovingVertically()); + QTest::touchEvent(&window, device).press(0, p); + QQuickTouchUtils::flush(&window); + for (int j = 0; j < 4 && !mouseArea->drag()->active(); ++j) { + p += QPoint(0, threshold); + QTest::touchEvent(&window, device).move(0, p); + QQuickTouchUtils::flush(&window); + } + // MouseArea should be dragged because of preventStealing; ListView does not steal the grab. + QVERIFY(mouseArea->drag()->active()); + QCOMPARE(flickable->isDragging(), false); + QTest::touchEvent(&window, device).release(0, p); + QCOMPARE(mouseArea->drag()->active(), false); + } +} + void tst_QQuickMouseArea::clickThrough() { // timestamp delay to avoid generating a double click |