From 6ef802ff6ed1cd234848b65fdad56dc3b0579cff Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 28 Feb 2014 11:07:11 +0100 Subject: [PATCH] QQuickWidget: handle hide and show events properly Task-number: QTBUG-37062 Change-Id: I3763385168eaa0ccd009ada563f56ea0251029a5 Reviewed-by: Gunnar Sletta --- src/quick/items/qquickrendercontrol.cpp | 20 ++++++++++++++++++++ src/quick/items/qquickrendercontrol_p.h | 1 + src/quickwidgets/qquickwidget.cpp | 17 +++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index faee1358a..16ed6f0e1 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -161,6 +161,26 @@ bool QQuickRenderControl::sync() return true; } +/*! + Stop rendering and release resources. This function is typically + called when the window is hidden. Requires a current context. + */ +void QQuickRenderControl::stop() +{ + Q_D(QQuickRenderControl); + if (!d->window) + return; + + QQuickWindowPrivate *cd = QQuickWindowPrivate::get(d->window); + cd->fireAboutToStop(); + cd->cleanupNodesOnShutdown(); + + if (!cd->persistentSceneGraph) { + d->rc->invalidate(); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + } +} + /*! Render the scenegraph using the current context. */ diff --git a/src/quick/items/qquickrendercontrol_p.h b/src/quick/items/qquickrendercontrol_p.h index 7255a9ae0..98dc94630 100644 --- a/src/quick/items/qquickrendercontrol_p.h +++ b/src/quick/items/qquickrendercontrol_p.h @@ -71,6 +71,7 @@ public: void polishItems(); void render(); bool sync(); + void stop(); QImage grab(); diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index d530e0c18..147762c66 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -769,18 +769,27 @@ void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e) d->offscreenWindow->mouseDoubleClickEvent(&mappedEvent); } -void QQuickWidget::showEvent(QShowEvent *e) +void QQuickWidget::showEvent(QShowEvent *) { Q_D(QQuickWidget); QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = true; - d->offscreenWindow->showEvent(e); + + d->updatePending = false; + triggerUpdate(); } -void QQuickWidget::hideEvent(QHideEvent *e) +void QQuickWidget::hideEvent(QHideEvent *) { Q_D(QQuickWidget); QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = false; - d->offscreenWindow->hideEvent(e); + + QOpenGLContext *context = d->offscreenWindow->openglContext(); + if (!context) { + qWarning("QQuickWidget::hideEvent with no context"); + return; + } + context->makeCurrent(d->offscreenWindow); + d->renderControl->stop(); } /*! \reimp */ -- 2.34.1