From d7a4f47e7d42af33858ff263823bd7cdbea98b57 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 25 Feb 2021 17:56:11 +0100 Subject: [PATCH] Improve HiDpi handling Add code stolen from QBitTorrent that enables properly HiDpi handling. HighDpi support is set by default starting with Qt 5.6. Support for fractional scaling is added for Qt >= 5.14. Hopefully fixes bug #12060. --- src/frontends/qt/GuiApplication.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 6395f8e98a..fc2210aa22 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -63,6 +63,7 @@ #include "support/convert.h" #include "support/debug.h" #include "support/ExceptionMessage.h" +#include "support/environment.h" #include "support/FileName.h" #include "support/filetools.h" #include "support/ForkedCalls.h" @@ -180,6 +181,19 @@ frontend::Application * createApplication(int & argc, char * argv[]) AllowSetForegroundWindow(ASFW_ANY); #endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + // Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created + if (getEnv("QT_ENABLE_HIGHDPI_SCALING").empty() + && getEnv("QT_AUTO_SCREEN_SCALE_FACTOR").empty()) + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + // HighDPI scale factor policy must be set before QGuiApplication is created + if (getEnv("QT_SCALE_FACTOR_ROUNDING_POLICY").empty()) + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); +#endif + frontend::GuiApplication * guiApp = new frontend::GuiApplication(argc, argv); // I'd rather do that in the constructor, but I do not think that // the palette is accessible there.