diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2023-07-05 16:25:52 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-07-06 12:11:28 +0000 |
commit | fd0a3c1e73aafa2229a8f552838e118db0045664 (patch) | |
tree | 46e793ab2a21582dc2bdb7db94ec5726c16836d3 | |
parent | 6cdb19ab2a21b6ff44d04319e8df77b49e541508 (diff) |
QQuickTableViewResizeHandler: don't accept events outside of us
Handlers can be sent events that are outside of the target
item, so check for that in wantsEventPoint.
Fixes: QTBUG-111013
Change-Id: I52f17fc7030a93d999188fe7608411f11d235858
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 345189c46917b9faa4d1b05ac7314cd78dd88c03)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
3 files changed, 56 insertions, 3 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index e058e1969b..c0eaecc43a 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -6584,6 +6584,7 @@ QQuickTableViewResizeHandler::QQuickTableViewResizeHandler(QQuickTableView *view // Set a grab permission that stops the flickable, as well as // any drag handler inside the delegate, from stealing the drag. setGrabPermissions(QQuickPointerHandler::CanTakeOverFromAnything); + setObjectName("tableViewResizeHandler"); } void QQuickTableViewResizeHandler::onGrabChanged(QQuickPointerHandler *grabber @@ -6612,8 +6613,9 @@ void QQuickTableViewResizeHandler::onGrabChanged(QQuickPointerHandler *grabber bool QQuickTableViewResizeHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) { - Q_UNUSED(event); - Q_UNUSED(point); + if (!QQuickSinglePointHandler::wantsEventPoint(event, point)) + return false; + // When the user is flicking, we disable resizing, so that // he doesn't start to resize by accident. auto tableView = static_cast<QQuickTableView *>(parentItem()->parent()); @@ -6719,6 +6721,7 @@ void QQuickTableViewResizeHandler::updateDrag(QPointerEvent *event, QEventPoint QQuickTableViewTapHandler::QQuickTableViewTapHandler(QQuickTableView *view) : QQuickTapHandler(view->contentItem()) { + setObjectName("tableViewTapHandler"); } bool QQuickTableViewTapHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) diff --git a/tests/auto/quickcontrols/qquickheaderview/data/resizableHandlerBlockingEvents.qml b/tests/auto/quickcontrols/qquickheaderview/data/resizableHandlerBlockingEvents.qml new file mode 100644 index 0000000000..0b520c3be3 --- /dev/null +++ b/tests/auto/quickcontrols/qquickheaderview/data/resizableHandlerBlockingEvents.qml @@ -0,0 +1,29 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +ApplicationWindow { + width: 800 + height: 600 + + ColumnLayout { + anchors.fill: parent + + Rectangle { + Layout.fillWidth: true + Layout.fillHeight: true + color: mouseArea.pressed ? "tomato" : "steelblue" + + MouseArea { + id: mouseArea + objectName: "mouseArea" + anchors.fill: parent + } + } + + HorizontalHeaderView { + Layout.fillWidth: true + Layout.fillHeight: true + } + } +} diff --git a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp index 28b92fef71..9ad1490299 100644 --- a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp @@ -8,13 +8,17 @@ #include <QAbstractItemModelTester> #include <QtQml/QQmlEngine> #include <QtQml/QQmlComponent> -#include <QtQuick/private/qquickwindow_p.h> +#include <QtQuick/private/qquickmousearea_p.h> #include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquickwindow_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtQuickTestUtils/private/visualtestutils_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickheaderview_p.h> #include <private/qquickheaderview_p_p.h> +using namespace QQuickVisualTestUtils; + class TestTableModel : public QAbstractTableModel { Q_OBJECT Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) @@ -196,6 +200,8 @@ private slots: void testModel(); void listModel(); + void resizableHandlerBlockingEvents(); + private: QQmlEngine *engine; QString errorString; @@ -376,6 +382,21 @@ void tst_QQuickHeaderView::listModel() QCOMPARE(vhvCell2->property("text"), "222"); } +// A header shouldn't block events outside of itself. +void tst_QQuickHeaderView::resizableHandlerBlockingEvents() +{ + QQuickApplicationHelper helper(this, QStringLiteral("resizableHandlerBlockingEvents.qml")); + QVERIFY2(helper.errorMessage.isEmpty(), helper.errorMessage); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + auto mouseArea = window->findChild<QQuickMouseArea *>("mouseArea"); + QVERIFY(mouseArea); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, mapCenterToWindow(mouseArea)); + QVERIFY(mouseArea->isPressed()); +} + QTEST_MAIN(tst_QQuickHeaderView) #include "tst_qquickheaderview.moc" |