Qt Declarative (Quick 2)
Go to file
Mitch Curtis 7be805d155 Resize offscreen window when QQuickWidget is resized
In a typical Qt Quick application, when a window is resized, the
contentItem of that window is resized with it, and then the root item.
QQuickOverlay in qtquickcontrols2 listens to size changes in the
contentItem (QQuickRootItem) via addItemChangeListener(), as a cheap
way (e.g. no signals) of knowing when to resize background dimming
effects. It resizes the dimmer item to the size of the window.

The first problem with QQuickWidget is that it only ever resizes the root item
when using the SizeRootObjectToView resize mode, and not the contentItem.

The second problem is that the root item is resized (via updateSize()) before
the window itself even has a size (which happens in
QQuickWidget::createFramebufferObject() via the call to
d->offscreenWindow->setGeometry()).

To demonstrate the second problem in detail, consider the following widget
hierarchy (written in everybody's favorite language: QML):

QMainWindow {
    QQuickWidget {
        QQuickWindow { // QQuickWidgetPrivate::offscreenWindow
            QQuickRootItem { // QQuickWindowPrivate::contentItem
                Page {} // QQuickWidgetPrivate::root
            }
        }
    }
}

The QMainWindow starts off as 200x200. When the window is resized,
QQuickWidget::resizeEvent() is called. The first thing it does is call
updateSize(), which in the case of SizeRootObjectToView, resizes the root item
to 300x300. This causes QQuickOverlayPrivate::itemGeometryChanged() to be
called, and the dimmers are resized to the size of the window, but the window
still has its 200x200 size, as it is only updated later, when
QQuickWidget::createFramebufferObject() is called.

This patch fixes these issues by ensuring that contentItem and the window
itself are resized along with the root item.

As to why such manual intervention is necessary: from what I can see, it is
because it's an "offscreen" window. This means that
QWindowPrivate::platformWindow is null, and setGeometry() takes a different
path that presumably results in no QResizeEvent being sent to the QQuickWindow.
As QQuickWindow relies on resizeEvent() being called to resize its contentItem,
the contentItem is never resized. With a typical Qt Quick application, all of
this works as expected.

Change-Id: I7401aa7a9b209096183416ab53014f67cceccbe4
Fixes: QTBUG-78323
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
2020-03-24 13:57:22 +01:00
config.tests/d3d12 D3D12: Support translucent windows via DirectComposition 2016-07-14 13:05:13 +00:00
dist Add changes file for Qt 5.14.1 2020-01-14 06:36:17 +01:00
examples Add missing QPainterPath include in rendernode example 2020-03-10 12:20:02 +01:00
features Add the skeleton for a D3D12 backend 2016-02-19 14:51:37 +00:00
src Resize offscreen window when QQuickWidget is resized 2020-03-24 13:57:22 +01:00
tests Resize offscreen window when QQuickWidget is resized 2020-03-24 13:57:22 +01:00
tools qmllint: Fix typo 2020-03-24 10:23:33 +01:00
.gitattributes
.gitignore Add .qmake.stash to .gitignore 2019-05-03 08:46:51 +00:00
.gitmodules Update to the latest version of the ecmascript test suite 2018-04-26 20:26:36 +00:00
.qmake.conf Bump version 2020-02-02 13:41:30 +01:00
.tag
LICENSE.FDL Add license files mandated by (L)GPL. 2013-02-15 00:03:10 +01:00
LICENSE.GPL2 Updated license headers 2016-01-19 14:53:18 +00:00
LICENSE.GPL3 Updated license headers 2016-01-19 14:53:18 +00:00
LICENSE.GPL3-EXCEPT Updated license headers 2016-01-20 11:46:25 +00:00
LICENSE.LGPL3 Updated license headers 2016-01-19 14:53:18 +00:00
configure.json Move model types into their own library 2019-05-02 09:26:04 +00:00
qtdeclarative.doxy Add doxyfile for building doxygen documentation 2018-08-16 15:54:40 +00:00
qtdeclarative.pro Convert qtdeclarative over to use the new configure system 2016-10-10 14:11:39 +00:00
sync.profile Move the header checking into ExecutableCompilationUnit 2019-06-14 19:08:51 +02:00