diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-02-29 16:22:49 -0700 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-05 02:45:17 +0000 |
commit | 9580f7970cc394e2a499a3b5b65d3391b5bb6442 (patch) | |
tree | bcd8909ea3acf94f4d16aba3d3d1425493b3f3f2 | |
parent | 9dc004dcd4fee2fdd5efd1b4edf11e55e56f3de4 (diff) |
QQuickWidget: don't set WA_AcceptTouchEvents on macOS
Usually, a QTouchEvent comes from a touchscreen, and we want those touch
events in Qt Quick. But on macOS, there are no touchscreens, and
WA_AcceptTouchEvents has a different meaning: since qtbase
03d057ff01332333b98f5298c3d0bd85b5604ac9, QApplication::notify()
calls the native-integration function registertouchwindow() to change
NSView::allowedTouchTypes to include NSTouchTypeMaskIndirect when the
trackpad cursor enters the window, and removes that mask when the cursor
exits. In other words, WA_AcceptTouchEvents enables getting discrete
touchpoints from the trackpad. We rather prefer to get mouse, wheel and
native gesture events from the trackpad (because those provide more of a
"native feel"). The only exception is for MultiPointTouchArea, and it
takes care of that for itself. So don't automatically set
WA_AcceptTouchEvents on macOS. The user can still do it, but we don't
recommend it. Amends dc8f44b14501ecd4acc196f5138aeff3f7502d0a
Fixes: QTBUG-113384
Pick-to: 6.5 6.2
Change-Id: I8b0e1d247adfc95f1c9a0881a6020eab1a42b0ab
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 2f1be4c51a1655697933468c10ba53316306d207)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 485388263f55ac7c40c53fa3b0d4bfaa275e55f1)
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 17 | ||||
-rw-r--r-- | tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp | 7 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index c2c0f6f8d3..205c9e31c7 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -612,7 +612,24 @@ QQuickWidget::QQuickWidget(QWidget *parent) { setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); +#ifndef Q_OS_MACOS + /* + Usually, a QTouchEvent comes from a touchscreen, and we want those + touch events in Qt Quick. But on macOS, there are no touchscreens, and + WA_AcceptTouchEvents has a different meaning: QApplication::notify() + calls the native-integration function registertouchwindow() to change + NSView::allowedTouchTypes to include NSTouchTypeMaskIndirect when the + trackpad cursor enters the window, and removes that mask when the + cursor exits. In other words, WA_AcceptTouchEvents enables getting + discrete touchpoints from the trackpad. We rather prefer to get mouse, + wheel and native gesture events from the trackpad (because those + provide more of a "native feel"). The only exception is for + MultiPointTouchArea, and it takes care of that for itself. So don't + automatically set WA_AcceptTouchEvents on macOS. The user can still do + it, but we don't recommend it. + */ setAttribute(Qt::WA_AcceptTouchEvents); +#endif d_func()->init(); } diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index 6d097409b0..6ff46ad983 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -703,7 +703,9 @@ void tst_qquickwidget::touchTapHandler() QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, guiSynthMouse); QQuickWidget quick; - QVERIFY(quick.testAttribute(Qt::WA_AcceptTouchEvents)); + if (!quick.testAttribute(Qt::WA_AcceptTouchEvents)) + QSKIP("irrelevant on non-touch platforms"); + quick.setSource(testFileUrl("tapHandler.qml")); quick.show(); QVERIFY(QTest::qWaitForWindowExposed(&quick)); @@ -728,6 +730,9 @@ void tst_qquickwidget::touchMultipleWidgets() QWidget window; QQuickWidget *leftQuick = new QQuickWidget; leftQuick->setSource(testFileUrl("button.qml")); + if (!leftQuick->testAttribute(Qt::WA_AcceptTouchEvents)) + QSKIP("irrelevant on non-touch platforms"); + QQuickWidget *rightQuick = new QQuickWidget; rightQuick->setSource(testFileUrl("button.qml")); |