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.

Pick-to: 5.15 6.2 6.3
Fixes: QTBUG-103522
Change-Id: Ib4a2b01b814835715642aec83fac0a84debe2461
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Shawn Rutledge 2022-05-18 13:21:05 +02:00
parent cc28d9d2a7
commit d92f1dfe05
3 changed files with 64 additions and 1 deletions

View File

@ -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;

View File

@ -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
}
}
}
}

View File

@ -125,6 +125,7 @@ private slots:
void invalidClick();
void pressedOrdering();
void preventStealing();
void preventStealingListViewChild();
void clickThrough();
void hoverPosition();
void hoverPropagation();
@ -1108,6 +1109,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