aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets/qquickwidget.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-14 09:52:51 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-22 09:40:41 +0100
commitdc8f44b14501ecd4acc196f5138aeff3f7502d0a (patch)
tree5cbfe4807d54588929eae948c4581b9f9a028cb3 /src/quickwidgets/qquickwidget.cpp
parent4cbc25f37908be48af9c5e2024069c9bb2f88a16 (diff)
QQuickWidget: always accept touch events and grabbed event points
A QQuickWidget contains a Quick UI, which can be expected to handle touch events, and it handles touch events by forwarding them to the QQuickWindow. So set the AcceptTouchEvents attribute and let the Qt Quick delivery machinery deal with the touch-mouse synthesis within the scene. Also, Qt Quick's event delivery might return event points as ignored after setting the exclusive grabber. Qt Widgets touch event delivery logic doesn't care about exclusive grabbers, and relies on the event points being accepted to make the widget that received the TouchBegin an implicit grabber. QQuickWidget needs to translate those states back, so accept all points that come back with a grabber. Add a test that verifies that a button in a popup gets all events, and that those events are translated correctly - without the fix, the "clicked" test fails, as the release is delivered, but with coordinates outside of the button. Also test that we can have two QQuickWidgets where each gets one touch point. Fixes: QTBUG-101736 Pick-to: 6.5 6.4 6.2 Change-Id: I3a2bf05fd297ae4d72b6e236ecd8e5ddac37ce06 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r--src/quickwidgets/qquickwidget.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index a59c3cd9fc..73f1ecf63c 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -613,6 +613,7 @@ QQuickWidget::QQuickWidget(QWidget *parent)
{
setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus);
+ setAttribute(Qt::WA_AcceptTouchEvents);
d_func()->init();
}
@@ -1632,9 +1633,23 @@ bool QQuickWidget::event(QEvent *e)
case QEvent::TouchBegin:
case QEvent::TouchEnd:
case QEvent::TouchUpdate:
- case QEvent::TouchCancel:
+ case QEvent::TouchCancel: {
// Touch events only have local and global positions, no need to map.
- return QCoreApplication::sendEvent(d->offscreenWindow, e);
+ bool res = QCoreApplication::sendEvent(d->offscreenWindow, e);
+ if (e->isAccepted() && e->type() == QEvent::TouchBegin) {
+ // If the TouchBegin got accepted, then make sure all points that have
+ // an exclusive grabber are also accepted so that the widget code for
+ // delivering touch events make this widget an implicit grabber of those
+ // points.
+ QPointerEvent *pointerEvent = static_cast<QPointerEvent *>(e);
+ auto deliveredPoints = pointerEvent->points();
+ for (auto &point : deliveredPoints) {
+ if (pointerEvent->exclusiveGrabber(point))
+ point.setAccepted(true);
+ }
+ }
+ return res;
+ }
case QEvent::FocusAboutToChange:
return QCoreApplication::sendEvent(d->offscreenWindow, e);