diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 4d8059273f..7625c452fb 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -795,6 +795,11 @@ void QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event) d->propagate(&me, QQuickMouseAreaPrivate::DoubleClick); if (d->pressed) d->doubleClick = d->isDoubleClickConnected() || me.isAccepted(); + + // do not call the base implementation if the event is accepted + // because it will revert the event back to ignored state + if (me.isAccepted()) + return; } QQuickItem::mouseDoubleClickEvent(event); } diff --git a/tests/auto/quick/pointerhandlers/mousearea_interop/data/doubleClickInMouseArea.qml b/tests/auto/quick/pointerhandlers/mousearea_interop/data/doubleClickInMouseArea.qml new file mode 100644 index 0000000000..e43a2f3160 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/mousearea_interop/data/doubleClickInMouseArea.qml @@ -0,0 +1,23 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Window + +Rectangle { + width: 200; height: 200 + color: mouseArea.pressed ? "red" : "orange" + + Popup { + visible: true + closePolicy: Popup.NoAutoClose + width: 100 + height: 100 + contentItem: MouseArea { + id: mouseArea + + anchors.fill: parent + } + background: Rectangle { + color: "green" + } + } +} diff --git a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp index 3c288cbb3b..a65a7d43d9 100644 --- a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp +++ b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp @@ -32,6 +32,7 @@ private slots: void dragHandlerInSiblingStealingGrabFromMouseAreaViaTouch(); void hoverHandlerDoesntHoverOnPress(); void doubleClickInMouseAreaWithDragHandlerInGrandparent(); + void doubleClickInMouseArea(); private: void createView(QScopedPointer &window, const char *fileName); @@ -204,6 +205,26 @@ void tst_MouseAreaInterop::doubleClickInMouseAreaWithDragHandlerInGrandparent() QCOMPARE(dragActiveSpy.size(), 0); } +void tst_MouseAreaInterop::doubleClickInMouseArea() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("doubleClickInMouseArea.qml"))); + + auto *ma = window.rootObject()->findChild(); + QVERIFY(ma); + QSignalSpy doubleClickSpy(ma, &QQuickMouseArea::doubleClicked); + QSignalSpy longPressSpy(ma, &QQuickMouseArea::pressAndHold); + QPoint p = ma->mapToScene(ma->boundingRect().center()).toPoint(); + + // check with normal double click + QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, p); + QCOMPARE(doubleClickSpy.count(), 1); + + // wait enough time for a wrong long press to happen + QTest::qWait(QGuiApplication::styleHints()->mousePressAndHoldInterval() + 10); + QCOMPARE(longPressSpy.count(), 0); +} + QTEST_MAIN(tst_MouseAreaInterop) #include "tst_mousearea_interop.moc"