summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2016-04-27 01:15:48 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2019-08-23 03:40:43 +0200
commit3e5362bfa123cfc0b56c77d5e34ad63ea6e9f89a (patch)
treec8fb7cd33a8497b44e4fafb0cefe9644df49e7c7 /tests/manual
parent900f2cb6f7070b4d426f3b83787ac489b8a2e827 (diff)
HighDPI: Add “metrics” manual test
This test displays a summary of relevant DPI and scale factor/devicePixelRatio values: - DPI and DPR as seen by the application - Input from QPlatformScreen - Input from environment variables. Task-number: QTBUG-53022 Change-Id: I340391624b202e342f22902ffbd7228fe7fbe94b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/highdpi/main.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index 7225587ac0..8884c5feed 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -37,10 +37,12 @@
#include <QPushButton>
#include <QButtonGroup>
#include <QLineEdit>
+#include <QPlainTextEdit>
#include <QScrollBar>
#include <QSlider>
#include <QSpinBox>
#include <QTabBar>
+#include <QTextBrowser>
#include <QIcon>
#include <QPainter>
#include <QWindow>
@@ -55,9 +57,16 @@
#include <QCommandLineOption>
#include <QDebug>
#include <private/qhighdpiscaling_p.h>
+#include <qpa/qplatformscreen.h>
#include "dragwidget.h"
+static QTextStream &operator<<(QTextStream &str, const QRect &r)
+{
+ str << r.width() << 'x' << r.height() << forcesign << r.x() << r.y() << noforcesign;
+ return str;
+}
+
class DemoContainerBase
{
public:
@@ -1176,6 +1185,85 @@ public:
}
};
+class MetricsTest : public QWidget
+{
+ QPlainTextEdit *m_textEdit;
+
+public:
+ MetricsTest()
+ {
+ qDebug() << R"(
+MetricsTest
+Relevant environment variables are:
+QT_FONT_DPI=N
+QT_SCALE_FACTOR=n
+QT_ENABLE_HIGHDPI_SCALING=0|1
+QT_USE_PHYSICAL_DPI=0|1
+QT_SCREEN_SCALE_FACTORS=N;N;N or QT_SCREEN_SCALE_FACTORS=name:N
+QT_SCALE_FACTOR_ROUNDING_POLICY=Round|Ceil|Floor|RoundPreferFloor|PassThrough
+QT_DPI_ADJUSTMENT_POLICY=AdjustDpi|DontAdjustDpi|AdjustUpOnly)";
+
+ resize(480, 360);
+
+ QVBoxLayout *layout = new QVBoxLayout();
+ setLayout(layout);
+
+ m_textEdit = new QPlainTextEdit;
+ m_textEdit->setReadOnly(true);
+ layout->addWidget(m_textEdit);
+ }
+
+ void updateMetrics()
+ {
+ QString text;
+ QTextStream str(&text);
+
+ auto currentScreen = windowHandle()->screen();
+ const auto screens = QGuiApplication::screens();
+ for (int i = 0, size = screens.size(); i < size; ++i) {
+ auto screen = screens.at(i);
+ auto platformScreen = screen->handle();
+ str << "Screen #" << i << " \"" << screen->name() << '"';
+ if (screen == currentScreen)
+ str << " [current]";
+ if (screen == QGuiApplication::primaryScreen())
+ str << " [primary]";
+ str << "\n screen geometry: " << screen->geometry()
+ << "\n platform screen geometry: " << platformScreen->geometry()
+ << "\n platform screen logicalDpi: " << platformScreen->logicalDpi().first;
+
+#ifdef HAVE_SCREEN_BASE_DPI
+ str << "\n platform screen logicalBaseDpi: " << platformScreen->logicalBaseDpi().first;
+#endif
+ str << "\n platform screen devicePixelRatio: " <<platformScreen->devicePixelRatio()
+ << "\n platform screen physicalDpi: " << screen->physicalDotsPerInch()
+ << "\n\n";
+ }
+
+ str << "widget devicePixelRatio: " << this->devicePixelRatioF()
+ << "\nwidget logicalDpi: " << this->logicalDpiX()
+ << "\n\nQT_FONT_DPI: " << qgetenv("QT_FONT_DPI")
+ << "\nQT_SCALE_FACTOR: " << qgetenv("QT_SCALE_FACTOR")
+ << "\nQT_ENABLE_HIGHDPI_SCALING: " << qgetenv("QT_ENABLE_HIGHDPI_SCALING")
+ << "\nQT_SCREEN_SCALE_FACTORS: " << qgetenv("QT_SCREEN_SCALE_FACTORS")
+ << "\nQT_USE_PHYSICAL_DPI: " << qgetenv("QT_USE_PHYSICAL_DPI")
+ << "\nQT_SCALE_FACTOR_ROUNDING_POLICY: " << qgetenv("QT_SCALE_FACTOR_ROUNDING_POLICY")
+ << "\nQT_DPI_ADJUSTMENT_POLICY: " << qgetenv("QT_DPI_ADJUSTMENT_POLICY")
+ << '\n';
+
+ m_textEdit->setPlainText(text);
+ }
+
+ void paintEvent(QPaintEvent *ev)
+ {
+ // We get a paint event on screen change, so this is a convenient place
+ // to update the metrics, at the possible risk of doing something else
+ // than painting in a paint event.
+ updateMetrics();
+ QWidget::paintEvent(ev);
+ }
+};
+
int main(int argc, char **argv)
{
QApplication app(argc, argv);
@@ -1212,6 +1300,7 @@ int main(int argc, char **argv)
demoList << new DemoContainer<ScreenDisplayer>("screens", "Test screen and window positioning");
demoList << new DemoContainer<PhysicalSizeTest>("physicalsize", "Test manual highdpi support using physicalDotsPerInch");
demoList << new DemoContainer<GraphicsViewCaching>("graphicsview", "Test QGraphicsView caching");
+ demoList << new DemoContainer<MetricsTest>("metrics", "Show display metrics");
foreach (DemoContainerBase *demo, demoList)
parser.addOption(demo->option());