diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-09-02 08:17:20 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-09-08 09:23:07 +0000 |
commit | 362f6999a52849482e73915ca37ed4b6cc9ff9aa (patch) | |
tree | a284281a027e4bf7c4b8afdd253df60375b6545d | |
parent | df40607e8afeca83dff634f1ab8cc3d335f9feb9 (diff) |
Propagate focusObjectChanged signal (second attempt)
When the focus object is updated from inside the Qt Quick scene,
the signal needs to be propagated from the offscreen window to
the widget's window, otherwise the input methods will not react
to it.
Also, we need to propagate the FocusAboutToChange event,
otherwise the contents of the editor will not be committed
when the focus object changes, and the input method can
get into an invalid state.
Fixes: QTBUG-61475
Change-Id: I44ba171c0e78ef8b2e0127cba8991f1f1cf13571
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 13 | ||||
-rw-r--r-- | src/quickwidgets/qquickwidget.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 1c9fc3ca69..bb9157d0e7 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -117,6 +117,7 @@ void QQuickWidgetPrivate::initOffscreenWindow() QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInitialized()), q, SLOT(createFramebufferObject())); QWidget::connect(offscreenWindow, SIGNAL(sceneGraphInvalidated()), q, SLOT(destroyFramebufferObject())); + QWidget::connect(offscreenWindow, &QQuickWindow::focusObjectChanged, q, &QQuickWidget::propagateFocusObjectChanged); } void QQuickWidgetPrivate::init(QQmlEngine* e) @@ -1547,6 +1548,9 @@ bool QQuickWidget::event(QEvent *e) // Touch events only have local and global positions, no need to map. return QCoreApplication::sendEvent(d->offscreenWindow, e); + case QEvent::FocusAboutToChange: + return QCoreApplication::sendEvent(d->offscreenWindow, e); + case QEvent::InputMethod: return QCoreApplication::sendEvent(d->offscreenWindow->focusObject(), e); case QEvent::InputMethodQuery: @@ -1795,6 +1799,15 @@ void QQuickWidget::paintEvent(QPaintEvent *event) } } +void QQuickWidget::propagateFocusObjectChanged(QObject *focusObject) +{ + Q_D(QQuickWidget); + if (QApplication::focusObject() != this) + return; + if (QWindow *window = d->windowHandle(QWidgetPrivate::WindowHandleMode::TopLevel)) + emit window->focusObjectChanged(focusObject); +} + #if QT_CONFIG(opengl) Q_CONSTRUCTOR_FUNCTION(qt_registerDefaultPlatformBackingStoreOpenGLSupport); #endif diff --git a/src/quickwidgets/qquickwidget.h b/src/quickwidgets/qquickwidget.h index 1ceb7449b3..fb7e5c5760 100644 --- a/src/quickwidgets/qquickwidget.h +++ b/src/quickwidgets/qquickwidget.h @@ -112,6 +112,7 @@ private Q_SLOTS: void createFramebufferObject(); void destroyFramebufferObject(); void triggerUpdate(); + void propagateFocusObjectChanged(QObject *focusObject); protected: void resizeEvent(QResizeEvent *) override; |