From 1471f2ae0924e5d124178d1953a14db889348da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Sun, 21 Feb 2021 20:46:22 +0100 Subject: Add deviceIndependentSize() to QPixmap and QImage This function returns the size in device independent pixels, and should be used when calculating user interface sizes. Change-Id: I528123f962595a3da42438ca560289a29aca4917 Reviewed-by: Volker Hilsheimer --- tests/auto/gui/image/qimage/tst_qimage.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/gui/image/qimage') diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 1554ac3602..12345b2a97 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -212,6 +212,7 @@ private slots: void cleanupFunctions(); void devicePixelRatio(); + void deviceIndependentSize(); void rgb30Unpremul(); void rgb30Repremul_data(); void rgb30Repremul(); @@ -3473,6 +3474,15 @@ void tst_QImage::devicePixelRatio() QCOMPARE(b.devicePixelRatio(), qreal(1.0)); } +void tst_QImage::deviceIndependentSize() { + QImage a(64, 64, QImage::Format_ARGB32); + a.fill(Qt::white); + a.setDevicePixelRatio(1.0); + QCOMPARE(a.deviceIndependentSize(), QSizeF(64, 64)); + a.setDevicePixelRatio(2.0); + QCOMPARE(a.deviceIndependentSize(), QSizeF(32, 32)); +} + void tst_QImage::rgb30Unpremul() { QImage a(3, 1, QImage::Format_A2RGB30_Premultiplied); -- cgit v1.2.3