diff options
author | Alessandro Portale <alessandro.portale@theqtcompany.com> | 2015-11-03 16:00:10 +0100 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@theqtcompany.com> | 2015-11-04 13:07:02 +0000 |
commit | f4e5210cda6e2db35a832fa9ad80e975ec06bc7b (patch) | |
tree | 3339cca57a9ceda066ccaed24478ce5b16a04b50 /src/app | |
parent | 2b16b97f19a93e9dc9b1465e196be1de34cdd4fa (diff) | |
download | qt-creator-f4e5210cda6e2db35a832fa9ad80e975ec06bc7b.tar.gz |
app: Setting HighDPI environment variables
After b42bd585c4d3a6c86efb5bc5ee0ec9f00a239dcf there was
no automatic scaling of Qt Creator's UI with Qt 5.6 on non-OSX,
anymore.
This commit re-introduces it for Windows.
As a small bonus, now the environment variable is only set during
QApplication creation and unset afterwards. The run environments
are now not affected, anymore.
Change-Id: If0039df500d28a93c1ca8c2df9960992a010723f
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/main.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp index 1cfccf42cf..ff239e06ff 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -159,6 +159,30 @@ static inline int askMsgSendFailed() QMessageBox::Retry); } +static const char* setHighDpiEnvirnonmentVariable() +{ + const char* envVarName = 0; + static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; +#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0)) + if (Utils::HostOsInfo().isWindowsHost() + && !qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)) { + envVarName = ENV_VAR_QT_DEVICE_PIXEL_RATIO; + qputenv(envVarName, "auto"); + } +#else + static const char ENV_VAR_QT_AUTO_SCREEN_SCALE_FACTOR[] = "QT_AUTO_SCREEN_SCALE_FACTOR"; + if (Utils::HostOsInfo().isWindowsHost() + && !qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) // legacy in 5.6, but still functional + && !qEnvironmentVariableIsSet(ENV_VAR_QT_AUTO_SCREEN_SCALE_FACTOR) + && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") + && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { + envVarName = ENV_VAR_QT_AUTO_SCREEN_SCALE_FACTOR; + qputenv(envVarName, "true"); + } +#endif // < Qt 5.6 + return envVarName; +} + // taken from utils/fileutils.cpp. We can not use utils here since that depends app_version.h. static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) @@ -280,12 +304,7 @@ static const char *SHARE_PATH = int main(int argc, char **argv) { -#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0)) - if (Utils::HostOsInfo().isWindowsHost() - && !qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO")) { - qputenv("QT_DEVICE_PIXEL_RATIO", "auto"); - } -#endif // < Qt 5.6 + const char *highDpiEnvironmentVariable = setHighDpiEnvirnonmentVariable(); QLoggingCategory::setFilterRules(QLatin1String("qtc.*.debug=false")); #ifdef Q_OS_MAC @@ -299,6 +318,9 @@ int main(int argc, char **argv) SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv); + if (highDpiEnvironmentVariable) + qunsetenv(highDpiEnvironmentVariable); + if (Utils::HostOsInfo().isWindowsHost() && !qFuzzyCompare(qApp->devicePixelRatio(), 1.0) && QApplication::style()->objectName().startsWith( |