diff options
authorRichard Moe Gustavsen <>2021-01-12 14:50:40 +0100
committerRichard Moe Gustavsen <>2021-01-14 10:47:02 +0100
commit9e4d9fca8a5ed0a10033345bc88b4ae39d20b952 (patch)
parent3b1cb25eb026e3a85d616df0b9ed20d508468694 (diff)
QGuiApplication: use global position to create local position for synthetic mouse events
When QWidgetWindow handles a QTouchEvent, it will call updateTouchPointsForWidget() for each widget it tries to deliver the touch event to. This will make sure that the point's position() is updated to be local to the widget being processed. The problem is that we never reset this overwriting of local positions in the event after we're done. So if we later try to synthesize a mouse event from it, the local position in the fake mouse event will be based on the local position inside a random widget, and not the original local position sent from QPA. Rather than trying to store all the original local positions inside the event before going through this delivery logic, and reset it afterwards, we base the local position of the synthesized mouse event on the (unmodified) global position instead. Fixes: QTBUG-90033 Pick-to: dev Change-Id: I1588351482de7cce9c06d102db3686ea8dd0c118 Reviewed-by: Jani Heikkinen <> Reviewed-by: Shawn Rutledge <>
1 files changed, 4 insertions, 1 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index d3ed576220..b6720a8e76 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2954,6 +2954,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
+ // Note: after the call to sendSpontaneousEvent, touchEvent.position() will have
+ // changed to reflect the local position inside the last (random) widget it tried
+ // to deliver the touch event to, and will therefore be invalid afterwards.
QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
@@ -2993,7 +2996,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
// left mouse button events instead (see AA_SynthesizeMouseForUnhandledTouchEvents docs).
// TODO why go through QPA? Why not just send a QMouseEvent right from here?
QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
- touchPoint->position(),
+ window->mapFromGlobal(touchPoint->globalPosition().toPoint()),