summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2021-03-12 14:49:09 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2021-03-15 11:49:59 +0100
commitf9f9004b40ed7a4f4d280ba48bf6422cac6d21a4 (patch)
tree5570db8c342691b2079110cd0257fbdbeb1add92 /tests/auto/gui
parentf0bf7667a9914d00c3b3510bd46bb94d573d7d1a (diff)
Add auto-test for QT_USE_PHYSICAL_DPI
Test that setting QT_USE_PHYSICAL_DPI uses physical DPI instead of logical DPI. Change-Id: I7f89cf1af5e013454cc3d8ec3559f2719514fea3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
index 339ff0ed20..31a41eeff6 100644
--- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
+++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
@@ -56,6 +56,7 @@ private slots:
void screenDpiAndDpr();
void environment_QT_SCALE_FACTOR();
void environment_QT_SCREEN_SCALE_FACTORS();
+ void environment_QT_USE_PHYSICAL_DPI();
void screenAt_data();
void screenAt();
void screenGeometry_data();
@@ -187,6 +188,7 @@ void tst_QHighDpi::cleanup()
// in order to avoid getting confusing follow-on errors on test failures.
qunsetenv("QT_SCALE_FACTOR");
qunsetenv("QT_SCREEN_SCALE_FACTORS");
+ qunsetenv("QT_USE_PHYSICAL_DPI");
}
void tst_QHighDpi::qhighdpiscaling_data()
@@ -273,6 +275,31 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS()
}
}
+void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI()
+{
+ qputenv("QT_USE_PHYSICAL_DPI", "1");
+
+ QList<qreal> dpiValues { 96, 144, 192 };
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ // Verify that the device pixel ratio is computed as physicalDpi / baseDpi.
+ // (which in practice uses physicalSize since this is what QPlatformScreen provides)
+
+ // The default QPlatformScreen::physicalSize() implementation (which QOffscreenScreen
+ // currerently uses) assumes a default DPI of 100 and calculates a fake physical size
+ // based on that value. Use DPI 100 here as well: if you have changed the default value
+ // in QPlatformScreen and get a test failure then update the value below.
+ const qreal platformScreenDefualtDpi = 100;
+ qreal expextedDpr = (platformScreenDefualtDpi / qreal(standardBaseDpi));
+
+ for (QScreen *screen : app->screens()) {
+ QCOMPARE(screen->devicePixelRatio(), expextedDpr);
+ QCOMPARE(screen->logicalDotsPerInch(), 96);
+ QWindow window(screen);
+ QCOMPARE(window.devicePixelRatio(), expextedDpr);
+ }
+}
+
void tst_QHighDpi::minimumDpr()
{
QList<qreal> dpiValues { 40, 60, 95 };