]> git.lyx.org Git - lyx.git/commitdiff
Improve HiDpi handling
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 25 Feb 2021 16:56:11 +0000 (17:56 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 4 Mar 2021 09:21:17 +0000 (10:21 +0100)
Add code stolen from QBitTorrent and Qt Creator that properly enables
HighDpi handling.

The rules are:

1/ nothing needs to be done for macOS and Qt >= 6

2/ HighDpi support is set by default starting with Qt 5.6.

3/ Support for fractional scaling is added for Qt >= 5.14.

Hopefully fixes bug #12060.

(cherry picked from commit d7a4f47e7d42af33858ff263823bd7cdbea98b57)
(cherry picked from commit f92f2f95ffd5f0d9d9704c9d7f67e4a9e74db0f6)

src/frontends/qt4/GuiApplication.cpp
status.23x

index 458e71198f8f9b4738b93629a5a910191e6a0304..29b708e0be98af2829901adb79cd327992ad16f4 100644 (file)
@@ -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"
@@ -194,6 +195,24 @@ frontend::Application * createApplication(int & argc, char * argv[])
        AllowSetForegroundWindow(ASFW_ANY);
 #endif
 
+
+// Setup high DPI handling. This is a bit complicated, but will be default in Qt6.
+// macOS does it by itself.
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_OS_MAC)
+#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
+#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.
index 06a0d577b9018ba061912308ffe1d6cf84cac3e7..441d2dd412fa2737af252e8f6edb9f499d8ede76 100644 (file)
@@ -34,8 +34,11 @@ What's new
 - Other than directly inserted, now references can also be pasted as insets
   into an equation, instead of simply as text (bug 11539). 
 
+- Add support for High DPI screens in Windows and Linux (bug 12060).
+
 - Add Qt platform name in About dialog.
 
+
 * DOCUMENTATION AND LOCALIZATION