summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-02-16 00:17:20 +0100
committerJukka Jokiniva <jukka.jokiniva@qt.io>2023-04-06 14:28:24 +0000
commita215e6650a3c9a1da8c6ae4b7a0038a1a073a1eb (patch)
tree4de94a85e862e1be1ba27abfe8055f38b4def5ea /tests/auto/gui/kernel
parent684d30198342880078b4fa11f3c71d35e1a2fa4f (diff)
Add DPI change tests
We can expand the testing a bit bit verifying that also created windows work as expected, and that QWindow DPR is updated when Screen DPI is changed. Change-Id: I082aac18b6b086c69c16681977b7eaa6c3e54ee0 Reviewed-by: Jukka Jokiniva <jukka.jokiniva@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
index 9a2482b03e..fdb835d70b 100644
--- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
+++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
@@ -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;