aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets/qquickwidget.cpp
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2024-05-02 17:28:30 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2024-05-06 11:15:47 +0000
commitb85ec1cab47e8cdc5383fc0c681cee8a9f453366 (patch)
tree2916fa83e5153389040432ac7f208063bde06d6a /src/quickwidgets/qquickwidget.cpp
parent3fa280b76bb9f3fc600c10683ad2186d9cdcf9cf (diff)
QQuickWidget: Set WA_AcceptTouchEvents in all constructors
So far this was set only in two of the three constructors. But all of them call init(). Amends 2f1be4c51a1655697933468c10ba53316306d207. Task-number: QTBUG-113384 Pick-to: 6.7 Change-Id: Ie15cad40164e6faea626c005fddbf54bedaf3ffe Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r--src/quickwidgets/qquickwidget.cpp43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 01f437fe30..0d119b1b49 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -200,6 +200,27 @@ void QQuickWidgetPrivate::init(QQmlEngine* e)
if (!engine.isNull() && !engine.data()->incubationController())
engine.data()->setIncubationController(offscreenWindow->incubationController());
+ q->setMouseTracking(true);
+ q->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.
+ */
+ q->setAttribute(Qt::WA_AcceptTouchEvents);
+#endif
+
#if QT_CONFIG(quick_draganddrop)
q->setAcceptDrops(true);
#endif
@@ -614,26 +635,6 @@ QImage QQuickWidgetPrivate::grabFramebuffer()
QQuickWidget::QQuickWidget(QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), 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();
}
@@ -660,8 +661,6 @@ QQuickWidget::QQuickWidget(const QUrl &source, QWidget *parent)
QQuickWidget::QQuickWidget(QQmlEngine* engine, QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, {})
{
- setMouseTracking(true);
- setFocusPolicy(Qt::StrongFocus);
d_func()->init(engine);
}