mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Allow to properly scale the GUI with Qt5
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.
This commit is contained in:
parent
da6e100ccb
commit
9e6cf6e05a
18
src/LyX.cpp
18
src/LyX.cpp
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user