diff options
author | YoungSun Park <cathy.park@lge.com> | 2019-08-16 21:32:22 +0900 |
---|---|---|
committer | Johannes Oikarinen <johannes.oikarinen@qt.io> | 2020-09-15 15:38:19 +0300 |
commit | 3ff11ceca37dcc4b6f0420332fa7f6aa007be7f3 (patch) | |
tree | f23018b359d2502527fc1a9706fb2152e2bc3197 /tests/auto/quick/qquickmousearea | |
parent | 6412bcd2219d2a5c1f8193d8f394ddb1279dee2b (diff) |
QQuickWindow: Consider z-order of children when delivering pointer events
When creating a target item list for handling pointer events, put
children after the parent item if they have negative z-order value.
This fixes an issue where an item does not receive a pointer event if
there is a child item that accepts the event even when that child item
is shown under the parent item as per the stacking order.
Fixes: QTBUG-83114
Pick-to: 5.15
Change-Id: I711faa22516f5c2396b1138dc507bcaa4ba22241
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickmousearea')
-rw-r--r-- | tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml | 37 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 34 |
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml b/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml new file mode 100644 index 0000000000..aba574283b --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/mouseAreasOverlapped.qml @@ -0,0 +1,37 @@ + +import QtQuick 2.0 + +Item { + width: 300 + height:200 + property var clicks: [] + + Rectangle { + x: 75 + y: 75 + width: 200 + height: 100 + color: "salmon" + + MouseArea { + objectName: "parentMouseArea" + anchors.fill: parent + onClicked: clicks.push(objectName) + } + + Rectangle { + x: 25 + y: 25 + width: 200 + height: 100 + color: "lightsteelblue" + + MouseArea { + id: mouseArea + objectName: "childMouseArea" + anchors.fill: parent + onClicked: clicks.push(objectName) + } + } + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index c38ab72a7b..7bf9660978 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -158,6 +158,7 @@ private slots: void mask(); void nestedEventDelivery(); void settingHiddenInPressUngrabs(); + void negativeZStackingOrder(); private: int startDragDistance() const { @@ -2438,6 +2439,39 @@ void tst_QQuickMouseArea::settingHiddenInPressUngrabs() QVERIFY(!mouseArea->pressed()); } +void tst_QQuickMouseArea::negativeZStackingOrder() // QTBUG-83114 +{ + QQuickView window; + QByteArray errorMessage; + QVERIFY2(QQuickTest::initView(window, testFileUrl("mouseAreasOverlapped.qml"), true, &errorMessage), errorMessage.constData()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != nullptr); + QQuickItem *root = window.rootObject(); + + QQuickMouseArea *parentMouseArea = root->findChild<QQuickMouseArea*>("parentMouseArea"); + QVERIFY(parentMouseArea != nullptr); + QSignalSpy clickSpyParent(parentMouseArea, &QQuickMouseArea::clicked); + QQuickMouseArea *childMouseArea = root->findChild<QQuickMouseArea*>("childMouseArea"); + QVERIFY(childMouseArea != nullptr); + QSignalSpy clickSpyChild(childMouseArea, &QQuickMouseArea::clicked); + + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100)); + QCOMPARE(clickSpyChild.count(), 1); + QCOMPARE(clickSpyParent.count(), 0); + auto order = root->property("clicks").toList(); + QVERIFY(order.at(0) == "childMouseArea"); + + // Now change stacking order and try again. + childMouseArea->parentItem()->setZ(-1); + root->setProperty("clicks", QVariantList()); + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100)); + QCOMPARE(clickSpyChild.count(), 1); + QCOMPARE(clickSpyParent.count(), 1); + order = root->property("clicks").toList(); + QVERIFY(order.at(0) == "parentMouseArea"); +} + QTEST_MAIN(tst_QQuickMouseArea) #include "tst_qquickmousearea.moc" |