]> git.lyx.org Git - features.git/commitdiff
Allow to properly scale the GUI with Qt5
authorEnrico Forestieri <forenr@lyx.org>
Sun, 22 Jan 2017 00:06:00 +0000 (01:06 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 22 Jan 2017 00:06:00 +0000 (01:06 +0100)
Starting with Qt 5.6, setting the environment variable QT_SCALE_FACTOR
makes everything accordingly bigger. So, if QT_SCALE_FACTOR=1.2, all
text and GUI elements are rendered 20% bigger. However, if an application
does not account for this, everything will also look "blocky".
With this commit, all text and images will be scaled remaining sharp.
This works whether a HiDpi screen is used or not, but is mostly useful
with a HiDpi screen, as all GUI elements are more spaced apart and one
can use the mouse for selecting things without requiring a high precision.

src/LyX.cpp
src/LyX.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiWorkArea.cpp

index 0f6b9b6acb45497873240cd060a5267aa4d47789..bf40298707950f7670783f247d840c0616e0a2bf 100644 (file)
@@ -52,6 +52,7 @@
 #include "frontends/Application.h"
 
 #include "support/ConsoleApplication.h"
+#include "support/convert.h"
 #include "support/lassert.h"
 #include "support/debug.h"
 #include "support/environment.h"
@@ -121,6 +122,14 @@ RunMode run_mode = PREFERRED;
 OverwriteFiles force_overwrite = UNSPECIFIED;
 
 
+// Scale the GUI by this factor. This works whether we have a HiDpi screen
+// or not and scales everything, also fonts. Can only be changed by setting
+// the QT_SCALE_FACTOR environment variable before launching LyX and only
+// works properly with Qt 5.6 or higher.
+
+double qt_scale_factor = 1.0;
+
+
 namespace {
 
 // Filled with the command line arguments "foo" of "-sysdir foo" or
@@ -303,6 +312,15 @@ int LyX::exec(int & argc, char * argv[])
        // we need to parse for "-dbg" and "-help"
        easyParse(argc, argv);
 
+       // Check whether Qt will scale all GUI elements and accordingly
+       // set the scale factor so that to avoid blurred images and text
+       char const * const scale_factor = getenv("QT_SCALE_FACTOR");
+       if (scale_factor) {
+               qt_scale_factor = convert<double>(scale_factor);
+               if (qt_scale_factor < 1.0)
+                       qt_scale_factor = 1.0;
+       }
+
        try {
                init_package(os::utf8_argv(0), cl_system_support, cl_user_support);
        } catch (ExceptionMessage const & message) {
index 11c67a311812ce11f9e53e4c449fd65012529733..85decbc6d66e3837eb6e36e38bc2ed4e1cbdd190 100644 (file)
--- a/src/LyX.h
+++ b/src/LyX.h
@@ -55,6 +55,7 @@ extern bool verbose;
 extern bool ignore_missing_glyphs;
 extern RunMode run_mode;
 extern OverwriteFiles force_overwrite;
+extern double qt_scale_factor;
 
 namespace frontend {
 class Application;
index 2f6f8f202b0ea328607650bdbca8cba023cb55ec..0eb55bad0266b8c6e43d336b1d9a51c3a1bcddf1 100644 (file)
@@ -1017,6 +1017,9 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        QCoreApplication::setOrganizationName(app_name);
        QCoreApplication::setOrganizationDomain("lyx.org");
        QCoreApplication::setApplicationName(lyx_package);
+#if QT_VERSION >= 0x050000
+       QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+#endif
 
        qsrand(QDateTime::currentDateTime().toTime_t());
 
@@ -1101,7 +1104,7 @@ GuiApplication * theGuiApp()
 double GuiApplication::pixelRatio() const
 {
 #if QT_VERSION >= 0x050000
-       return devicePixelRatio();
+       return qt_scale_factor * devicePixelRatio();
 #else
        return 1.0;
 #endif
index 2c481245680727876bc3d2c5f4171cec0a3608fb..a6b5877be1e67a9f8a114c65d378ef828136e273 100644 (file)
@@ -227,7 +227,7 @@ private:
        /// Current ratio between physical pixels and device-independent pixels
        double pixelRatio() const {
 #if QT_VERSION >= 0x050000
-               return devicePixelRatio();
+               return qt_scale_factor * devicePixelRatio();
 #else
                return 1.0;
 #endif
@@ -1341,7 +1341,7 @@ void GuiView::resetCommandExecute()
 double GuiView::pixelRatio() const
 {
 #if QT_VERSION >= 0x050000
-       return devicePixelRatio();
+       return qt_scale_factor * devicePixelRatio();
 #else
        return 1.0;
 #endif
index aa5e285da733a6e6bdb76727f5a08368e6b44d57..8a023726b2f11018f4fd1b3be9709031305abb40 100644 (file)
@@ -275,7 +275,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
 double GuiWorkArea::pixelRatio() const
 {
 #if QT_VERSION >= 0x050000
-       return devicePixelRatio();
+       return qt_scale_factor * devicePixelRatio();
 #else
        return 1.0;
 #endif