diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-08-20 10:43:34 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-23 14:53:24 +0000 |
commit | 5189268ccccf132ee6a9ac69aa09e51099394dba (patch) | |
tree | 81fe57174b4bef9e4158484e0cfd059d4925f0df /tests | |
parent | cf460a005bb4b510aaee97aed626630980691666 (diff) |
Handle redirected rendering better in styles
Unlike in the QWidget-based desktop world, Qt Quick scenes can
be rendered in a variety of ways, some completely offscreen
wthout any native windows on screen, whereas some (most notably,
QQuickWidget) work offscreen but in association with an on-screen
window that is not the QQuickWindow. Therefore, every time a
QQuickWindow is accessed, typically from QQuickStyleItem, it needs
to be considered if further resolution is needed.
For devicePixelRatio, there is a handy helper available in form of
QQuickWindow::effectiveDevicePixelRatio(). This picks up the dpr
from either the QQuickWindow or the QQuickWidget's associated
top-level QWidget window (or whatever window a custom
QQuickRenderControl implementation reports).
Elsewhere, where we need a QWindow in order to do native window
things, QQuickRenderControl::renderWindowFor() must be called to see
if there is another QWindow we should be using in place of the
QQuickWindow.
Fixes: QTBUG-95937
Change-Id: I0690915d995ebb5f5cc0c48f565dfaf978e849ea
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io>
(cherry picked from commit 6ee6b49bce210d7e86f68009a332360051f0e8fc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quickwidgets/qquickwidget/data/controls.qml | 23 | ||||
-rw-r--r-- | tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp | 31 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/quickwidgets/qquickwidget/data/controls.qml b/tests/auto/quickwidgets/qquickwidget/data/controls.qml new file mode 100644 index 0000000000..3e415f33da --- /dev/null +++ b/tests/auto/quickwidgets/qquickwidget/data/controls.qml @@ -0,0 +1,23 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Rectangle { + id: root + ColumnLayout { + anchors.fill: parent + ComboBox { + } + Button { + text: "Button" + } + CheckBox { + text: "CheckBox" + } + RadioButton { + text: "RadioButton" + } + TextField { + } + } +} diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index 6ae0dc12ac..c902cf56b3 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -144,6 +144,7 @@ private slots: void synthMouseFromTouch(); void tabKey(); void resizeOverlay(); + void controls(); private: QPointingDevice *device = QTest::createTouchDevice(); @@ -735,6 +736,36 @@ void tst_qquickwidget::resizeOverlay() QCOMPARE(overlay->height(), rootItem->height()); } +void tst_qquickwidget::controls() +{ + // Smoke test for having some basic Quick Controls in a scene in a QQuickWidget. + QWidget widget; + QVBoxLayout *contentVerticalLayout = new QVBoxLayout(&widget); + QQuickWidget *quickWidget = new QQuickWidget(testFileUrl("controls.qml"), &widget); + QCOMPARE(quickWidget->status(), QQuickWidget::Ready); + quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); + contentVerticalLayout->addWidget(quickWidget); + + widget.resize(400, 400); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + + QQuickItem *rootItem = qobject_cast<QQuickItem *>(quickWidget->rootObject()); + QVERIFY(rootItem); + QCOMPARE(rootItem->size(), quickWidget->size()); + QSize oldSize = quickWidget->size(); + + // Verify that QTBUG-95937 no longer occurs. (on Windows with the default + // native windows style this used to assert in debug builds) + widget.resize(300, 300); + QTRY_VERIFY(quickWidget->width() < oldSize.width()); + QTRY_COMPARE(rootItem->size(), quickWidget->size()); + + widget.hide(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); +} + QTEST_MAIN(tst_qquickwidget) #include "tst_qquickwidget.moc" |