From 651ecf9ae413478af622761e89347bb4e6243e0c Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 24 Aug 2016 12:40:23 +0200 Subject: Fix mouse area pressed after removal of pre-grab Qt Quick used to actively "grab" the mouse before delivering events, making the code more complex than necessary. Some items came to rely on the behavior and now lack the ungrab event. This is triggered when inside the delivery of a mouse event, some other item grabs the mouse. If the mouse grab changed to an item that was not the target of the original delivery, the grab must have been stolen, so call mouseUngrabEvent in this case. Test case by J-P Nurmi. Task-number: QTBUG-55325 Change-Id: I2f0ac9d8aed1415662196070fb763f2752004d22 Reviewed-by: Shawn Rutledge --- .../auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/quick/qquickmousearea') diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 7baff93574..b69c6eedf8 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -125,6 +125,7 @@ private slots: void containsPress_data(); void containsPress(); void ignoreBySource(); + void notPressedAfterStolenGrab(); private: int startDragDistance() const { @@ -1987,6 +1988,23 @@ void tst_QQuickMouseArea::ignoreBySource() QCOMPARE(flickable->contentY(), 0.); } +void tst_QQuickMouseArea::notPressedAfterStolenGrab() +{ + QQuickWindow window; + window.resize(200, 200); + window.show(); + QTest::qWaitForWindowExposed(&window); + + QQuickMouseArea *ma = new QQuickMouseArea(window.contentItem()); + ma->setSize(window.size()); + QObject::connect(ma, + static_cast(&QQuickMouseArea::pressed), + [&]() { window.contentItem()->grabMouse(); }); + + QTest::mouseClick(&window, Qt::LeftButton); + QVERIFY(!ma->pressed()); +} + QTEST_MAIN(tst_QQuickMouseArea) #include "tst_qquickmousearea.moc" -- cgit v1.2.3