aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2023-04-04 14:19:42 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-04-12 01:09:42 +0000
commitd61f8a30af216774635a845c529a8cc4fb0153f7 (patch)
tree79581c1a41f9e5b445c74f84efc62f278ac61829 /tests
parent981c6262d896202df511070962c2663e901de0de (diff)
Ignore tap events for table view when interactive is disabled
TableView uses QQuickTapHandler internally to handle tap events. This handler accepts tap events considering pointerNavigationEnabled property of table view. TableView accepts mouse events if either 'interactive' or 'pointerNavigationEnabled' property is set as true, otherwise, it has to pass mouse or touch events to the below item. This patch introduces QQuickTableViewTapHandler inherited from QQuickTapHandler that can explicitly check pointerNavigationEnabled property of QQuickTableView during wantsEventPoint to either accept or ignore tap events. Fixes: QTBUG-108596 Change-Id: I330ae319706b6dbadc3a7319f62d636708aab995 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 79d61b3ab7fcc75454b81d5e78d4f404a9c4bd6c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/data/tableviewinteractive.qml32
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp42
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml
new file mode 100644
index 0000000000..526313dc24
--- /dev/null
+++ b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml
@@ -0,0 +1,32 @@
+import QtQuick
+import QtQuick.Controls
+
+Item {
+ id: rootItem
+
+ width: 200
+ height: 200
+ visible: true
+
+ property int eventCount: 0
+ property alias tableView: tableView
+
+ MouseArea {
+ anchors.fill: parent
+ onPressed: function(mouse) {
+ ++eventCount
+ }
+ }
+
+ TableView {
+ id: tableView
+ objectName: "tableView"
+ anchors.fill: parent
+ model: 1
+ delegate: Rectangle {
+ color: "red"
+ implicitWidth: 200
+ implicitHeight: 200
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 96412bad18..46b6dc03f4 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -245,6 +245,7 @@ private slots:
void deletedDelegate();
void columnResizing_data();
void columnResizing();
+ void tableViewInteractive();
void rowResizing_data();
void rowResizing();
void rowAndColumnResizing_data();
@@ -6143,6 +6144,47 @@ void tst_QQuickTableView::deletedDelegate()
QTRY_COMPARE(tv->delegate(), nullptr);
}
+void tst_QQuickTableView::tableViewInteractive()
+{
+ LOAD_TABLEVIEW("tableviewinteractive.qml");
+
+ auto *root = view->rootObject();
+ QVERIFY(root);
+ auto *window = root->window();
+ QVERIFY(window);
+
+ int eventCount = root->property("eventCount").toInt();
+ QCOMPARE(eventCount, 0);
+
+ // Event though we make 'interactive' as false, the TableView has
+ // pointerNacigationEnabled set as true by default, which allows it to consume
+ // mouse events and thus, eventCount still be zero
+ tableView->setInteractive(false);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ eventCount = root->property("eventCount").toInt();
+ QCOMPARE(eventCount, 0);
+
+ // Making both 'interactive' and 'pointerNavigationEnabled' as false, doesn't
+ // allow TableView (and its parent Flickable) to consume mouse event and it
+ // passes to the below visual item
+ tableView->setInteractive(false);
+ tableView->setPointerNavigationEnabled(false);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ eventCount = root->property("eventCount").toInt();
+ QCOMPARE(eventCount, 1);
+
+ // Making 'interactive' as true and 'pointerNavigationEnabled' as false,
+ // allows parent of TableView (i.e. Flickable) to consume mouse events
+ tableView->setInteractive(true);
+ tableView->setPointerNavigationEnabled(false);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ eventCount = root->property("eventCount").toInt();
+ QCOMPARE(eventCount, 1);
+}
+
void tst_QQuickTableView::columnResizing_data()
{
QTest::addColumn<int>("column");