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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Aaron Barany
2023-08-02 16:11:18 -07:00
parent 9c2527eea6
commit d1deeb2c0d

View File

@@ -278,26 +278,16 @@ static Utils::QtcSettings *createUserSettings()
static void setHighDpiEnvironmentVariable() static void setHighDpiEnvironmentVariable()
{ {
if (Utils::HostOsInfo::isMacHost()) if (Utils::HostOsInfo::isMacHost() || qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY"))
return; return;
std::unique_ptr<QSettings> settings(createUserSettings()); std::unique_ptr<QSettings> settings(createUserSettings());
const bool defaultValue = Utils::HostOsInfo::isWindowsHost(); const bool defaultValue = Utils::HostOsInfo::isWindowsHost();
const bool enableHighDpiScaling = settings->value("Core/EnableHighDpiScaling", defaultValue).toBool(); const bool enableHighDpiScaling = settings->value("Core/EnableHighDpiScaling", defaultValue).toBool();
const auto policy = enableHighDpiScaling ? Qt::HighDpiScaleFactorRoundingPolicy::PassThrough
static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; : Qt::HighDpiScaleFactorRoundingPolicy::Floor;
if (enableHighDpiScaling QGuiApplication::setHighDpiScaleFactorRoundingPolicy(policy);
&& !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);
} }
void setPixmapCacheLimit() void setPixmapCacheLimit()