From d49d7c1d82cc326e4cad18f809b68bb4c777657b Mon Sep 17 00:00:00 2001 From: Nick Korotysh Date: Tue, 3 Mar 2020 23:39:17 +0300 Subject: [PATCH] Delegate GUI scaling work to Qt Set Qt::AA_EnableHighDpiScaling application attribute when Qt 5.14.x or newer is used. This fixes a lot of scaling issues on HiDPI displays. Unfortunately, this flag must be set only before QApllication object creation, so the only one place where it can be done is main(). --- src/app/main.cpp | 6 ++++++ src/gui/utils.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/app/main.cpp b/src/app/main.cpp index 2a9f84862..d9a8686ac 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -133,6 +133,12 @@ int main(int argc, char *argv[]) // We must save it here because QApplication constructor may change it bool isOneArg = (argc == 2); +#if !defined(DISABLE_GUI) && (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + // Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created + if (qgetenv("QT_ENABLE_HIGHDPI_SCALING").isEmpty() && qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR").isEmpty()) + Application::setAttribute(Qt::AA_EnableHighDpiScaling, true); +#endif + try { // Create Application const QString appId = QLatin1String("qBittorrent-") + Utils::Misc::getUserIDString(); diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index 63bcfe647..ec66d4bb2 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -62,6 +62,10 @@ void Utils::Gui::resize(QWidget *widget, const QSize &newSize) qreal Utils::Gui::screenScalingFactor(const QWidget *widget) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + Q_UNUSED(widget); + return 1; +#else if (!widget) return 1; @@ -77,6 +81,7 @@ qreal Utils::Gui::screenScalingFactor(const QWidget *widget) #else return widget->devicePixelRatioF(); #endif // Q_OS_WIN +#endif // QT_VERSION } QPixmap Utils::Gui::scaledPixmap(const QIcon &icon, const QWidget *widget, const int height)