Skip to content

Commit 68f6e50

Browse files
committed
Add DPI logging
And related settings
1 parent 081f78e commit 68f6e50

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

qrgui/mainWindow/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static QString versionInfo()
7373

7474
int main(int argc, char *argv[])
7575
{
76-
PlatformInfo::enableHiDPISupport();
76+
const auto &dpiInfo = PlatformInfo::enableHiDPISupport();
7777
QScopedPointer<QRealApplication> app(new QRealApplication(argc, argv));
7878

7979
if (app->arguments().contains("--clear-conf")) {
@@ -124,6 +124,7 @@ int main(int argc, char *argv[])
124124
<< "/ Kernel: " << QSysInfo::kernelType() << QSysInfo::kernelVersion();
125125
QLOG_INFO() << "Arguments:" << app->arguments();
126126
QLOG_INFO() << "Setting default locale to" << QLocale().name();
127+
for (auto &&i: dpiInfo) { QLOG_INFO() << i ; }
127128

128129
QApplication::setStyle(QStyleFactory::create("Fusion"));
129130

qrgui/mainWindow/mainWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ MainWindow::MainWindow(const QString &fileToOpen)
114114
, mSceneCustomizer(new SceneCustomizer())
115115
, mInitialFileToOpen(fileToOpen)
116116
{
117+
QLOG_INFO() << "MainWindow: screen DPI is" << logicalDpiX();
117118
mUi->setupUi(this);
118119
mUi->paletteTree->initMainWindow(this);
119120
setWindowTitle("QReal");

qrkernel/platformInfo.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,25 @@ bool PlatformInfo::isX64()
119119
return cpuArchitecture().contains("64");
120120
}
121121

122-
void PlatformInfo::enableHiDPISupport()
122+
QStringList PlatformInfo::enableHiDPISupport()
123123
{
124-
if (!qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO")
125-
&& !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
126-
&& !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
127-
&& !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
128-
// Only if there is no attempt to set from the system environment
129-
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
124+
static const QList<const char*> envVars { "QT_DEVICE_PIXEL_RATIO"
125+
, "QT_AUTO_SCREEN_SCALE_FACTOR"
126+
, "QT_SCALE_FACTOR"
127+
, "QT_SCREEN_SCALE_FACTORS"
128+
};
129+
bool anyIsSet = false;
130+
QStringList result;
131+
for (auto &&e: envVars) {
132+
if (qEnvironmentVariableIsSet(e)) {
133+
result << QString("Scaling variable %1=%2").arg(e, qEnvironmentVariable(e));
134+
anyIsSet = true;
135+
}
136+
}
137+
if (!anyIsSet) {
138+
// Only if there is no attempt to set from the system environment
139+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
140+
result << "Using Qt::AA_EnableHighDpiScaling";
130141
}
142+
return result;
131143
}

qrkernel/platformInfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma once
1616

1717
#include <qrkernel/kernelDeclSpec.h>
18+
#include <QStringList>
1819

1920
namespace qReal {
2021

@@ -49,8 +50,8 @@ class QRKERNEL_EXPORT PlatformInfo
4950
/// Returns true if current OS and process architecture reported by currentCpuArchitecture contains '64'.
5051
static bool isX64();
5152

52-
/// Designed to make an attempt to set proper flags for HiDPI screens
53-
static void enableHiDPISupport();
53+
/// Designed to make an attempt to set proper flags for HiDPI screens, returns info for logging
54+
static QStringList enableHiDPISupport();
5455
};
5556

5657
}

0 commit comments

Comments
 (0)