Skip to content

Commit

Permalink
Don't set focus when moving the cursor with a touch pad
Browse files Browse the repository at this point in the history
On macOS, swiping with a single finger on the track pad (which Qt
identifies as a QInputDevice::DeviceType::TouchPad) results in a
TouchBegin event. For widgets that accept touch events (perhaps
implicitly because they want pan gestures, like QGraphicsView),
this results in a TouchBegin event to be delivered.

QApplication::notify will then check the widget's focus policy, and with
ClickFocus set, will set focus on the widget.

This is not what we want for a TouchBegin on a touch pad, so skip the
setting of the focus for that device type.

Pick-to: 6.5
Fixes: QTBUG-112922
Change-Id: Ie828793a784cc0e2fa47954bf5b396d6a44bd5e8
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
vohi committed Apr 28, 2023
1 parent c2f01d4 commit 127e33d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/widgets/kernel/qapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3062,7 +3062,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
bool eventAccepted = touchEvent->isAccepted();
bool acceptTouchEvents = w->testAttribute(Qt::WA_AcceptTouchEvents);

if (acceptTouchEvents && e->spontaneous()) {
if (acceptTouchEvents && e->spontaneous()
&& touchEvent->device()->type() != QInputDevice::DeviceType::TouchPad) {
const QPoint localPos = touchEvent->points()[0].position().toPoint();
QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, localPos);
}
Expand Down

0 comments on commit 127e33d

Please sign in to comment.