summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp')
-rw-r--r--tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
index 9a2482b03e..6fe4faec03 100644
--- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
+++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <private/qhighdpiscaling_p.h>
#include <qpa/qplatformscreen.h>
@@ -36,6 +36,7 @@ private slots:
void screenDpiAndDpr_data();
void screenDpiAndDpr();
void screenDpiChange();
+ void screenDpiChangeWithWindow();
void environment_QT_SCALE_FACTOR();
void environment_QT_SCREEN_SCALE_FACTORS_data();
void environment_QT_SCREEN_SCALE_FACTORS();
@@ -238,6 +239,9 @@ void tst_QHighDpi::screenDpiAndDpr()
QWindow window(screen);
QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
+ window.setGeometry(QRect(screen->geometry().center(), QSize(10, 10)));
+ window.create();
+ QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
}
}
@@ -264,12 +268,48 @@ void tst_QHighDpi::screenDpiChange()
for (QScreen *screen : app->screens()) {
QCOMPARE(screen->devicePixelRatio(), newDpi / standardBaseDpi);
QCOMPARE(screen->logicalDotsPerInch(), newDpi / screen->devicePixelRatio());
+
QWindow window(screen);
QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
+ window.create();
+ QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
}
QCOMPARE(app->devicePixelRatio(), newDpi / standardBaseDpi);
}
+void tst_QHighDpi::screenDpiChangeWithWindow()
+{
+ QList<qreal> dpiValues = { 96, 192, 288 };
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ // Create windows for screens
+ QList<QScreen *> screens = app->screens();
+ QList<QWindow *> windows;
+ for (int i = 0; i < screens.count(); ++i) {
+ QScreen *screen = screens[i];
+ QWindow *window = new QWindow();
+ windows.append(window);
+ window->setGeometry(QRect(screen->geometry().center(), QSize(10, 10)));
+ window->create();
+ QCOMPARE(window->devicePixelRatio(), dpiValues[i] / standardBaseDpi);
+ }
+
+ // Change screen DPI
+ QList<qreal> newDpiValues = { 288, 192, 96 };
+ QJsonValue config = offscreenConfiguration();
+ QCborMap map = QCborMap::fromJsonObject(config.toObject());
+ for (int i = 0; i < screens.count(); ++i) {
+ map[QLatin1String("screens")][i][QLatin1String("logicalDpi")] = newDpiValues[i];
+ }
+ setOffscreenConfiguration(map.toJsonObject());
+
+ // Verify that window DPR changes on Screen DPI change.
+ for (int i = 0; i < screens.count(); ++i) {
+ QWindow *window = windows[i];
+ QCOMPARE(window->devicePixelRatio(), newDpiValues[i] / standardBaseDpi);
+ }
+}
+
void tst_QHighDpi::environment_QT_SCALE_FACTOR()
{
qreal factor = 3.1415;