From cf1fbfea745c510986776965e7f3ffe7c9d65018 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 15 Oct 2019 13:53:46 +0200 Subject: Fix visibility regression when using offscreen window in qquickwidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since s 7ded77d in declarative we keep offscreen window in QQuickWidget as not visible to make input delivery system happy and due to fact that window is really not visible. However, this breaks some behavior in case that "emulated" visibility is required. Switch to track qwindow in case of rendercontrol instead of internal offscreen window. Task-number: QTBUG-79213 Change-Id: If98deb8c56c3ae3c053f4e4d21e6b3b69211a9c3 Reviewed-by: Christian Strømme --- src/webview/qquickviewcontroller.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/webview/qquickviewcontroller.cpp b/src/webview/qquickviewcontroller.cpp index 85050d6..11895d6 100644 --- a/src/webview/qquickviewcontroller.cpp +++ b/src/webview/qquickviewcontroller.cpp @@ -233,22 +233,36 @@ void QQuickViewController::geometryChanged(const QRectF &newGeometry, const QRec void QQuickViewController::onWindowChanged(QQuickWindow* window) { QQuickWindow *oldParent = qobject_cast(m_view->parentView()); - if (oldParent != 0) + if (oldParent) oldParent->disconnect(this); - if (window != 0) { - connect(window, &QQuickWindow::widthChanged, this, &QQuickViewController::scheduleUpdatePolish); - connect(window, &QQuickWindow::heightChanged, this, &QQuickViewController::scheduleUpdatePolish); - connect(window, &QQuickWindow::xChanged, this, &QQuickViewController::scheduleUpdatePolish); - connect(window, &QQuickWindow::yChanged, this, &QQuickViewController::scheduleUpdatePolish); - connect(window, &QQuickWindow::sceneGraphInitialized, this, &QQuickViewController::scheduleUpdatePolish); - connect(window, &QQuickWindow::sceneGraphInvalidated, this, &QQuickViewController::onSceneGraphInvalidated); - connect(window, &QQuickWindow::visibleChanged, this, [this](bool visible) { m_view->setVisible(visible); }); + if (!window) { + m_view->setParentView(nullptr); + return; } - // Check if there's an actual window available. + // Check if there's an actual native window available. QWindow *rw = QQuickRenderControl::renderWindowFor(window); - m_view->setParentView(rw ? rw : window); + + if (rw) { + connect(rw, &QWindow::widthChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(rw, &QWindow::heightChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(rw, &QWindow::xChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(rw, &QWindow::yChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(rw, &QWindow::visibleChanged, this, [this](bool visible) { m_view->setVisible(visible); }); + connect(window, &QQuickWindow::sceneGraphInitialized, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::sceneGraphInvalidated, this, &QQuickViewController::onSceneGraphInvalidated); + m_view->setParentView(rw); + } else { + connect(window, &QWindow::widthChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QWindow::heightChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QWindow::xChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QWindow::yChanged, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::sceneGraphInitialized, this, &QQuickViewController::scheduleUpdatePolish); + connect(window, &QQuickWindow::sceneGraphInvalidated, this, &QQuickViewController::onSceneGraphInvalidated); + connect(window, &QWindow::visibleChanged, this, [this](bool visible) { m_view->setVisible(visible); }); + m_view->setParentView(window); + } } void QQuickViewController::onVisibleChanged() -- cgit v1.2.3