From d1deeb2c0d2c3f22be7d970e5e0f166f5101667b Mon Sep 17 00:00:00 2001 From: Aaron Barany Date: Wed, 2 Aug 2023 16:11:18 -0700 Subject: [PATCH] App: Use PassThrough high DPI rounding policy When high DPI is enabled, use PassThrough rounding policy to allow for fractional scaling without having to manually set an environment variable. The high DPI setting is now respected even if various Qt scale/ratio environment variables are set, which is the case in valid default situations such as setting the global scaling factor for KDE Plasma. Task-number: QTCREATORBUG-29461 Change-Id: Ife2820d205b3440646255dc997744b2b8867bc70 Reviewed-by: Reviewed-by: Cristian Adam --- src/app/main.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index d4c4a47b8c8..46233ba19ca 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -278,26 +278,16 @@ static Utils::QtcSettings *createUserSettings() static void setHighDpiEnvironmentVariable() { - if (Utils::HostOsInfo::isMacHost()) + if (Utils::HostOsInfo::isMacHost() || qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY")) return; std::unique_ptr settings(createUserSettings()); const bool defaultValue = Utils::HostOsInfo::isWindowsHost(); const bool enableHighDpiScaling = settings->value("Core/EnableHighDpiScaling", defaultValue).toBool(); - - static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; - if (enableHighDpiScaling - && !qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) // legacy in 5.6, but still functional - && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") - && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") - && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { - return; - } - - if (!qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY")) - QGuiApplication::setHighDpiScaleFactorRoundingPolicy( - Qt::HighDpiScaleFactorRoundingPolicy::Floor); + const auto policy = enableHighDpiScaling ? Qt::HighDpiScaleFactorRoundingPolicy::PassThrough + : Qt::HighDpiScaleFactorRoundingPolicy::Floor; + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(policy); } void setPixmapCacheLimit()