From da650dd913939042973804a7cd8c02b1fb18b66c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 22 Jun 2016 12:09:40 +0200 Subject: Make QQuickWidget honor QQuickWindow::isPersistentSceneGraph Make the behavior compatible with QQuickWindow. [ChangeLog][QtQuick][Important Behavior Changes] QQuickWidget now follows the same behavior as QQuickWindow when it comes to the persistent scenegraph setting controlled by QQuickWindow::setPersistentSceneGraph(). In earlier releases the setting was ignored and the scenegraph was torn down on every hide event. This is not the case anymore. Task-number: QTBUG-54133 Change-Id: I2a68948c92b7b4e6dabf2c9323955f1b47563d65 Reviewed-by: Andy Nichols --- src/quickwidgets/qquickwidget.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/quickwidgets') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 775f6f5698..4a98122fea 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -402,6 +402,22 @@ QObject *QQuickWidgetPrivate::focusObject() entire purpose of QQuickWidget is to render Quick scenes without a separate native window, hence making it a native widget should always be avoided. + \section1 Scene graph and context persistency + + QQuickWidget honors QQuickWindow::isPersistentSceneGraph(), meaning that + applications can decide - by calling + QQuickWindow::setPersistentSceneGraph() on the window returned from the + quickWindow() function - to let scenegraph nodes and other Qt Quick scene + related resources be released whenever the widget becomes hidden. By default + persistency is enabled, just like with QQuickWindow. + + When running with the OpenGL backend of the scene graph, QQuickWindow + offers the possibility to disable persistent OpenGL contexts as well. This + setting is currently ignored by QQuickWidget and the context is always + persistent. The OpenGL context is thus not destroyed when hiding the + widget. The context is destroyed only when the widget is destroyed or when + the widget gets reparented into another top-level widget's child hierarchy. + \section1 Limitations Putting other widgets underneath and making the QQuickWidget transparent will not lead @@ -777,8 +793,9 @@ void QQuickWidgetPrivate::createContext() { #ifndef QT_NO_OPENGL Q_Q(QQuickWidget); - // On hide-show we invalidate() but our context is kept. - // We nonetheless need to initialize() again. + + // On hide-show we may invalidate() (when !isPersistentSceneGraph) but our + // context is kept. We may need to initialize() again, though. const bool reinit = context && !offscreenWindow->openglContext(); if (!reinit) { @@ -812,9 +829,10 @@ void QQuickWidgetPrivate::createContext() offscreenSurface->create(); } - if (context->makeCurrent(offscreenSurface)) - renderControl->initialize(context); - else + if (context->makeCurrent(offscreenSurface)) { + if (!offscreenWindow->openglContext()) + renderControl->initialize(context); + } else #endif qWarning("QQuickWidget: Failed to make context current"); } @@ -1230,7 +1248,8 @@ void QQuickWidget::showEvent(QShowEvent *) void QQuickWidget::hideEvent(QHideEvent *) { Q_D(QQuickWidget); - d->invalidateRenderControl(); + if (!d->offscreenWindow->isPersistentSceneGraph()) + d->invalidateRenderControl(); QWindowPrivate *offscreenPrivate = QWindowPrivate::get(d->offscreenWindow); if (offscreenPrivate->visible) { offscreenPrivate->visible = false; -- cgit v1.2.3