summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/manual/highdpi/dprgadget/CMakeLists.txt1
-rw-r--r--tests/manual/highdpi/dprgadget/main.cpp161
2 files changed, 128 insertions, 34 deletions
diff --git a/tests/manual/highdpi/dprgadget/CMakeLists.txt b/tests/manual/highdpi/dprgadget/CMakeLists.txt
index 94e9833474..e53f095739 100644
--- a/tests/manual/highdpi/dprgadget/CMakeLists.txt
+++ b/tests/manual/highdpi/dprgadget/CMakeLists.txt
@@ -14,6 +14,7 @@ qt_add_executable(dprgadget
target_link_libraries(dprgadget PUBLIC
Qt::Core
Qt::Gui
+ Qt::GuiPrivate
Qt::Widgets
)
diff --git a/tests/manual/highdpi/dprgadget/main.cpp b/tests/manual/highdpi/dprgadget/main.cpp
index 1cb1134bde..42a0e79c8c 100644
--- a/tests/manual/highdpi/dprgadget/main.cpp
+++ b/tests/manual/highdpi/dprgadget/main.cpp
@@ -26,8 +26,11 @@
**
****************************************************************************/
-#include <QtWidgets/QtWidgets>
#include <QtGui/qpa/qplatformscreen.h>
+#include <QtGui/qpa/qplatformwindow.h>
+#include <QtGui/private/qhighdpiscaling_p.h>
+#include <QtWidgets/QtWidgets>
+#include <iostream>
/*
DprGadget: The focused High-DPI settings debug utility
@@ -40,8 +43,12 @@
an utility which displays all inputs.
*/
-bool g_qtUsePhysicalDpi = false;
bool g_qtScaleFactor = false;
+bool g_qtUsePhysicalDpi = false;
+bool g_qtFontDpi = false;
+bool g_qtScaleFactorRoundingPolicy = false;
+bool g_displayEvents = false;
+
class DprGadget : public QWidget
{
@@ -49,10 +56,13 @@ public:
std::function<void(void)> m_clearFn;
std::function<void(void)> m_updateFn;
qreal m_currentDpr = -1;
+ QString m_eventsText;
DprGadget() {
- setWindowTitle("DprGadget");
+ setWindowTitle(QString("DprGadget - Qt %1").arg(qVersion()));
+ QFont tinyFont;
+ tinyFont.setPointSize(8);
QFont smallFont;
smallFont.setPointSize(12);
QFont bigFont;
@@ -68,71 +78,148 @@ public:
dprValue->setFont(biggerFont);
dprValue->setTextInteractionFlags(Qt::TextSelectableByMouse);
- QLabel *dpiLabel = new QLabel("Logical DPI:");
- dpiLabel->setFont(smallFont);
- dpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ QLabel *screenLabel = new QLabel("Current Screen:");
+ screenLabel->setFont(smallFont);
QLabel *sizeLabel = new QLabel("Window size:");
sizeLabel->setFont(smallFont);
sizeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ QLabel *nativeSizeLabel = new QLabel("Native:");
+ nativeSizeLabel->setFont(smallFont);
+ nativeSizeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QLabel *dpiLabel = new QLabel("Logical DPI:");
+ dpiLabel->setFont(smallFont);
+ dpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QLabel *windowDpiLabel = new QLabel("Window DPI:");
+ windowDpiLabel->setFont(smallFont);
+ windowDpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
QLabel *platformDpiLabel = new QLabel("Native Device Pixel Ratio:");
- QLabel *plarformDprLabel = new QLabel("Native Logical DPI:");
platformDpiLabel->setFont(smallFont);
platformDpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QLabel *windowDprLabel = new QLabel("Window DPR:");
+ windowDprLabel->setFont(smallFont);
+ windowDprLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
+
+ QLabel *plarformDprLabel = new QLabel("Native DPI:");
plarformDprLabel->setFont(smallFont);
plarformDprLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- QLabel *screenLabel = new QLabel("Current Screen:");
- screenLabel->setFont(smallFont);
+ QLabel *qtScaleFactorLabel = new QLabel("Qt Internal Scale Factor:");
+ qtScaleFactorLabel->setFont(smallFont);
+
+ QLabel *eventsLabel = new QLabel(m_eventsText);
+ eventsLabel->setFont(tinyFont);
+ eventsLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(dprLabel);
layout->setAlignment(dprLabel, Qt::AlignHCenter);
layout->addWidget(dprValue);
layout->setAlignment(dprValue, Qt::AlignHCenter);
- layout->addWidget(sizeLabel);
bool displayLogicalDpi = false;
if (displayLogicalDpi)
layout->addWidget(dpiLabel);
- if (g_qtScaleFactor) {
- QString text = QString("QT_SCALE_FACTOR ") + qgetenv("QT_SCALE_FACTOR");
- layout->addWidget(new QLabel(text));
- }
-
layout->addStretch();
- layout->addWidget(screenLabel);
- layout->addWidget(platformDpiLabel);
- layout->addWidget(plarformDprLabel);
+
+ QHBoxLayout *screenLabelLayout = new QHBoxLayout();
+ screenLabelLayout->addStretch();
+ screenLabelLayout->addWidget(screenLabel);
+ screenLabelLayout->addStretch();
+ layout->addLayout(screenLabelLayout);
+
+ QHBoxLayout *windowSizeLayout = new QHBoxLayout();
+ windowSizeLayout->addWidget(sizeLabel);
+ windowSizeLayout->addStretch();
+ windowSizeLayout->addWidget(nativeSizeLabel);
+ layout->addLayout(windowSizeLayout);
+
+ QHBoxLayout *dpiLayout = new QHBoxLayout();
+ dpiLayout->addWidget(windowDpiLabel);
+ dpiLayout->addStretch();
+ dpiLayout->addWidget(platformDpiLabel);
+ layout->addLayout(dpiLayout);
+
+ QHBoxLayout *dprLayout = new QHBoxLayout();
+ dprLayout->addWidget(windowDprLabel);
+ dprLayout->addStretch();
+ dprLayout->addWidget(plarformDprLabel);
+ layout->addLayout(dprLayout);
+
+ QHBoxLayout *qtScaleFactorLabelLayout = new QHBoxLayout();
+ qtScaleFactorLabelLayout->addStretch();
+ qtScaleFactorLabelLayout->addWidget(qtScaleFactorLabel);
+ qtScaleFactorLabelLayout->addStretch();
+ layout->addLayout(qtScaleFactorLabelLayout);
+
+ if (g_displayEvents)
+ layout->addWidget(eventsLabel);
+
+ bool activeEnvironment = g_qtScaleFactor || g_qtUsePhysicalDpi || g_qtFontDpi || g_qtScaleFactorRoundingPolicy;
+ if (activeEnvironment) {
+ layout->addWidget(new QLabel("Active Environment:"));
+ if (g_qtScaleFactor) {
+ QString text = QString("QT_SCALE_FACTOR=") + qgetenv("QT_SCALE_FACTOR");
+ layout->addWidget(new QLabel(text));
+ }
+ if (g_qtUsePhysicalDpi) {
+ QString text = QString("QT_USE_PHYSICAL_DPI=") + qgetenv("QT_USE_PHYSICAL_DPI");
+ layout->addWidget(new QLabel(text));
+ }
+ if (g_qtFontDpi) {
+ QString text = QString("QT_FONT_DPI=") + qgetenv("QT_FONT_DPI");
+ layout->addWidget(new QLabel(text));
+ }
+ if (g_qtScaleFactorRoundingPolicy) {
+ QString text = QString("QT_SCALE_FACTOR_ROUNDING_POLICY=") + qgetenv("QT_SCALE_FACTOR_ROUNDING_POLICY");
+ layout->addWidget(new QLabel(text));
+ }
+
+ }
auto updateValues = [=]() {
dprValue->setText(QString("%1").arg(devicePixelRatioF()));
+ windowDpiLabel->setText(QString("QWindow DPI: %1").arg(logicalDpiX()));
dpiLabel->setText(QString("Logical DPI: %1").arg(logicalDpiX()));
- sizeLabel->setText(QString("Window size: %1 %2").arg(width()).arg(height()));
+ sizeLabel->setText(QString("QWindow size: %1 %2").arg(width()).arg(height()));
+ QPlatformWindow *platformWindow = windowHandle()->handle();
+ nativeSizeLabel->setText(QString("native size %1 %2").arg(platformWindow->geometry().width())
+ .arg(platformWindow->geometry().height()));
QPlatformScreen *pscreen = screen()->handle();
+ if (g_qtUsePhysicalDpi) {
+ int physicalDpi = qRound(pscreen->geometry().width() / pscreen->physicalSize().width() * qreal(25.4));
+ platformDpiLabel->setText(QString("Native Physical DPI: %1").arg(physicalDpi));
+ } else {
+ platformDpiLabel->setText(QString("native logical DPI: %1").arg(pscreen->logicalDpi().first));
+ }
- if (g_qtUsePhysicalDpi)
- platformDpiLabel->setText(QString("Native Physical DPI: TODO"));
- else
- platformDpiLabel->setText(QString("Native Logical DPI: %1").arg(pscreen->logicalDpi().first));
-
- plarformDprLabel->setText(QString("Native Device Pixel Ratio: %1").arg(pscreen->devicePixelRatio()));
+ windowDprLabel->setText(QString("QWindow DPR: %1").arg(windowHandle()->devicePixelRatio()));
+ plarformDprLabel->setText(QString("native DPR: %1").arg(pscreen->devicePixelRatio()));
screenLabel->setText(QString("Current Screen: %1").arg(screen()->name()));
+ qtScaleFactorLabel->setText(QString("Qt Internal Scale Factor: %1").arg(QHighDpiScaling::factor(windowHandle())));
+ eventsLabel->setText(QString(m_eventsText));
};
m_updateFn = updateValues;
m_clearFn = [=]() {
dprValue->setText(QString(""));
+ m_eventsText.clear();
};
create();
- QObject::connect(this->windowHandle(), &QWindow::screenChanged, [updateValues](QScreen *screen){
+ QObject::connect(this->windowHandle(), &QWindow::screenChanged, [updateValues, this](QScreen *screen){
Q_UNUSED(screen);
+ this->m_eventsText.prepend(QString("ScreenChange "));
+ this->m_eventsText.truncate(80);
updateValues();
});
@@ -142,6 +229,12 @@ public:
}
void paintEvent(QPaintEvent *) override {
+
+ // Update the UI in the paint event - normally not good
+ // practice but it looks like we can get away with it here
+ this->m_eventsText.prepend(QString("Paint "));
+ this->m_eventsText.truncate(80);
+
// Dpr change should trigger a repaint, update display values here
if (m_currentDpr == devicePixelRatioF())
return;
@@ -150,7 +243,10 @@ public:
m_updateFn();
}
- void resizeEvent(QResizeEvent *) override {
+ void resizeEvent(QResizeEvent *event) override {
+ QSize size = event->size();
+ m_eventsText.prepend(QString("Resize(%1 %2) ").arg(size.width()).arg(size.height()));
+ m_eventsText.truncate(80);
m_updateFn();
}
@@ -168,18 +264,15 @@ int main(int argc, char **argv) {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
- // react to (some) high-dpi eviornment variables.
- g_qtUsePhysicalDpi = qgetenv("QT_USE_PHYSICAL_DPI") == QByteArray("1");
+ // Display any set high-dpi eviornment variable.
g_qtScaleFactor = qEnvironmentVariableIsSet("QT_SCALE_FACTOR");
+ g_qtUsePhysicalDpi = qgetenv("QT_USE_PHYSICAL_DPI") == QByteArray("1");
+ g_qtFontDpi = qEnvironmentVariableIsSet("QT_FONT_DPI");
+ g_qtScaleFactorRoundingPolicy = qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY");
QApplication app(argc, argv);
DprGadget dprGadget;
-
- // Set initial size. We expect this size to be preserved across screen
- // and DPI changes
- dprGadget.resize(560, 380);
-
dprGadget.show();
return app.exec();