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 Pick-to: 6.4 6.5 Change-Id: I330ae319706b6dbadc3a7319f62d636708aab995 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
fa3b472c13
commit
79d61b3ab7
|
@ -4713,7 +4713,7 @@ void QQuickTableViewPrivate::init()
|
|||
positionYAnimation.setProperty(QStringLiteral("contentY"));
|
||||
positionYAnimation.setEasing(QEasingCurve::OutQuart);
|
||||
|
||||
auto tapHandler = new QQuickTapHandler(q->contentItem());
|
||||
auto tapHandler = new QQuickTableViewTapHandler(q);
|
||||
|
||||
hoverHandler = new QQuickTableViewHoverHandler(q);
|
||||
resizeHandler = new QQuickTableViewResizeHandler(q);
|
||||
|
@ -6640,6 +6640,20 @@ void QQuickTableViewResizeHandler::updateDrag(QPointerEvent *event, QEventPoint
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
QQuickTableViewTapHandler::QQuickTableViewTapHandler(QQuickTableView *view)
|
||||
: QQuickTapHandler(view->contentItem())
|
||||
{
|
||||
}
|
||||
|
||||
bool QQuickTableViewTapHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point)
|
||||
{
|
||||
auto tableView = static_cast<QQuickTableView *>(parentItem()->parent());
|
||||
auto tableViewPrivate = QQuickTableViewPrivate::get(tableView);
|
||||
return tableViewPrivate->pointerNavigationEnabled && QQuickTapHandler::wantsEventPoint(event, point);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qquicktableview_p.cpp"
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <QtQuick/private/qquickselectable_p.h>
|
||||
#include <QtQuick/private/qquicksinglepointhandler_p.h>
|
||||
#include <QtQuick/private/qquickhoverhandler_p.h>
|
||||
#include <QtQuick/private/qquicktaphandler_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -108,6 +109,21 @@ protected:
|
|||
QPointerEvent *ev, QEventPoint &point) override;
|
||||
};
|
||||
|
||||
/*! \internal
|
||||
* QQuickTableViewTapHandler used to handle tap events explicitly for table view
|
||||
*/
|
||||
class QQuickTableViewTapHandler : public QQuickTapHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QQuickTableViewTapHandler(QQuickTableView *view);
|
||||
bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override;
|
||||
|
||||
friend class QQuickTableViewPrivate;
|
||||
};
|
||||
|
||||
|
||||
class Q_QUICK_PRIVATE_EXPORT QQuickTableViewPrivate : public QQuickFlickablePrivate, public QQuickSelectable
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue