diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-09-23 16:55:10 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-10-07 11:08:41 +0200 |
commit | 6857ad3e686a5e2b45d28a7f47dca3210608da50 (patch) | |
tree | 1769fe1b9a26a690f2b6c641ffac7492df28edf3 /tests | |
parent | 49391fcc41d871836868452b8300938d0b94f00e (diff) |
QQuickListView: prevent mouse delivery in floating header or footer
Earlier we reimplemented the contains() method of ListView to prevent
dragging in an Overlay or Pullback header or footer. But in QQuickWindow
(QQuickWindowPrivate::pointerTargets()), an early check prevents
delivery of pointer events to an item that is clipped and for which
contains() returns false, and also to its children. In that case, the
header or footer no longer responds to a mouse event even if you put a
MouseArea in it.
Reverts 6ad3445f1e159d9beea936b66d267dcaacdc5d6c; reimplemented using
similar logic in a new QQuickListViewPrivate::wantsPointerEvent()
method, overriding QQuickFlickablePrivate::wantsPointerEvent(), which
is now checked in event-handling code in addition to checking the
interactive flag.
Done-with: Wang Chuan <ouchuanm@outlook.com>
Pick-to: 5.15
Task-number: QTBUG-74046
Fixes: QTBUG-85302
Change-Id: I9474f035d26b74ee36c0ac19e45a77de2e694bf1
Reviewed-by: Wang Chuan <ouchuanm@outlook.com>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicklistview/data/clickHeaderAndFooterWhenClip.qml | 60 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 27 |
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/data/clickHeaderAndFooterWhenClip.qml b/tests/auto/quick/qquicklistview/data/clickHeaderAndFooterWhenClip.qml new file mode 100644 index 0000000000..c48e2d47d1 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/clickHeaderAndFooterWhenClip.qml @@ -0,0 +1,60 @@ +import QtQuick 2.9 +import QtQuick.Window 2.15 + +ListView { + id: list + anchors.fill: parent + property bool headerPressed: false + property bool footerPressed: false + model: ListModel { + ListElement { + name: "Element 1" + } + ListElement { + name: "Element 2" + } + ListElement { + name: "Element 3" + } + ListElement { + name: "Element 4" + } + ListElement { + name: "Element 5" + } + ListElement { + name: "Element 6" + } + } + clip: true + headerPositioning: ListView.OverlayHeader + footerPositioning: ListView.OverlayHeader + + delegate: Text { + height: 100 + text: name + } + + header: Rectangle { + width: parent.width + height: 50 + z: 2 + color: "blue" + MouseArea { + objectName: "header" + anchors.fill: parent + onClicked: list.headerPressed = true + } + } + footer: Rectangle { + width: parent.width + height: 50 + color: "red" + z: 2 + MouseArea { + objectName: "footer" + anchors.fill: parent + onClicked: list.footerPressed = true + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 132c42ec1f..51a753c199 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -298,6 +298,7 @@ private slots: void objectModelCulling(); void requiredObjectListModel(); + void clickHeaderAndFooterWhenClip(); private: template <class T> void items(const QUrl &source); @@ -10075,6 +10076,32 @@ void tst_QQuickListView::requiredObjectListModel() } } +void tst_QQuickListView::clickHeaderAndFooterWhenClip() // QTBUG-85302 +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("clickHeaderAndFooterWhenClip.qml")); + window->resize(640, 480); + window->show(); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + auto *root = window->rootObject(); + QVERIFY(root); + + auto *header = root->findChild<QQuickItem *>("header"); + QVERIFY(header); + + auto *footer = root->findChild<QQuickItem *>("footer"); + QVERIFY(footer); + + QVERIFY(root->property("headerPressed").isValid() && root->property("headerPressed").canConvert<bool>() && !root->property("headerPressed").toBool()); + QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, header->mapToItem(root, QPoint(header->width() / 2, header->height() / 2)).toPoint()); + QVERIFY(root->property("headerPressed").toBool()); + + QVERIFY(root->property("footerPressed").isValid() && root->property("footerPressed").canConvert<bool>() && !root->property("footerPressed").toBool()); + QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, footer->mapToItem(root, QPoint(footer->width() / 2, footer->height() / 2)).toPoint()); + QVERIFY(root->property("footerPressed").toBool()); +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" |