From c2db9b6a48ac979057be640013655c815a153e21 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 28 Aug 2014 12:23:46 +0200 Subject: QQuickWidget: Keep the offscreen quick window size in sync The resizing logic has some faults: The size change is not always communicated to the offscreen QQuickWindow. When hiding and showing a QQuickWidget we may return early from the resize event handler, skipping the geometry change for the offscreen window. This is wrong. To make sure the sizes always match, set the geometry together with the FBO creation instead. This is much more robust and guarantees that the FBO size and the QQuickWindow size will not be out of sync. Task-number: QTBUG-40517 Change-Id: I61ef3ad2d23dff4280dbf03b57c03c1aeda8dc91 Reviewed-by: Paul Olav Tvete --- src/quickwidgets/qquickwidget.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/quickwidgets/qquickwidget.cpp') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index e85b0fe2e0..285b000bdc 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -703,8 +703,13 @@ void QQuickWidget::createFramebufferObject() QSize fboSize = size() * window()->devicePixelRatio(); - delete d->fbo; - d->fbo = new QOpenGLFramebufferObject(fboSize, format); + // Could be a simple hide - show, in which case the previous fbo is just fine. + if (!d->fbo || d->fbo->size() != fboSize) { + delete d->fbo; + d->fbo = new QOpenGLFramebufferObject(fboSize, format); + } + + d->offscreenWindow->setGeometry(0, 0, width(), height()); d->offscreenWindow->setRenderTarget(d->fbo); if (samples > 0) @@ -891,8 +896,8 @@ void QQuickWidget::resizeEvent(QResizeEvent *e) } if (d->context) { - // Bail out in the special case of receiving a resize after - // scenegraph invalidation during application exit. + // Bail out when receiving a resize after scenegraph invalidation. This can happen + // during hide - resize - show sequences and also during application exit. if (!d->fbo && !d->offscreenWindow->openglContext()) return; if (!d->fbo || d->fbo->size() != size() * devicePixelRatio()) { @@ -906,9 +911,6 @@ void QQuickWidget::resizeEvent(QResizeEvent *e) d->createContext(); } - QCoreApplication::sendEvent(d->offscreenWindow, e); - d->offscreenWindow->setGeometry(0, 0, e->size().width(), e->size().height()); - QOpenGLContext *context = d->offscreenWindow->openglContext(); if (!context) { qWarning("QQuickWidget::resizeEvent() no OpenGL context"); -- cgit v1.2.3