diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2023-04-17 18:03:09 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-04-24 07:11:28 +0000 |
commit | 398926db49e9e287355f613a240b3f87805ab032 (patch) | |
tree | 648160bc5e05a7900706fe65d979ebba6bf1fb7a /tests | |
parent | 62e265b1908e355447d67600836a58a0fdc209af (diff) |
QQuickItem: item stays pressed after DoubleClicks
Amends 72651a50f83aa72998822312c7b5c6235d28978f.
This commit decided to ignore double clicks in the virtual
QQuickItem::mouseDoubleClickEvent().
If a subclass inheriting from QQuickItem wants to not ignore
a double click, it should override mouseDoubleClickEvent()
and handle the double click event accordingly.
Fix QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event) to *not*
call the base implementation in QQuickItem after handling a double
click, because QQuickItem sets that double-click MouseEvent back to
the ignored state.
This was leading to weird behavior on platforms with touch
screens like Android or IOS where buttons "got stuck" after
a double click.
Fixes: QTBUG-112434
Fixes: QTBUG-109393
Change-Id: I774189fbcb356b07336f35f053e05a12c34ce602
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit d7fac6923a6d4e4ac7dc22458256366968acbdb3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/pointerhandlers/mousearea_interop/data/doubleClickInMouseArea.qml | 23 | ||||
-rw-r--r-- | tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp | 21 |
2 files changed, 44 insertions, 0 deletions
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 556acbc828..833aa8ff32 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<QQuickView> &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<QQuickMouseArea *>(); + 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" |