From 5189268ccccf132ee6a9ac69aa09e51099394dba Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 20 Aug 2021 10:43:34 +0200 Subject: 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 Reviewed-by: Mitch Curtis Reviewed-by: Richard Moe Gustavsen Reviewed-by: Samuel Ghinet (cherry picked from commit 6ee6b49bce210d7e86f68009a332360051f0e8fc) Reviewed-by: Qt Cherry-pick Bot --- .../quickwidgets/qquickwidget/data/controls.qml | 23 ++++++++++++++++ .../quickwidgets/qquickwidget/tst_qquickwidget.cpp | 31 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/auto/quickwidgets/qquickwidget/data/controls.qml (limited to 'tests') 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(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" -- cgit v1.2.3