Enabling high-DPI scaling in QApplication

This commit is contained in:
Matthias Koefferlein 2022-09-22 21:13:23 +02:00
parent 1107e5bacc
commit c8889504e6
3 changed files with 22 additions and 6 deletions

View File

@ -302,6 +302,7 @@ klayout_main_cont (int &argc, char **argv)
if (non_ui_mode) {
app.reset (new lay::NonGuiApplication (argc, argv));
} else {
lay::GuiApplication::initialize ();
app.reset (new lay::GuiApplication (argc, argv));
lay::enable_signal_handler_gui (true);
}

View File

@ -1434,12 +1434,6 @@ GuiApplication::GuiApplication (int &argc, char **argv)
setStyle (new lay::BackgroundAwareTreeStyle (0));
setWindowIcon (QIcon (QString::fromUtf8 (":/logo.png")));
#if QT_VERSION >= 0x040500
setAttribute (Qt::AA_DontShowIconsInMenus, false);
#endif
#if QT_VERSION >= 0x050000
setAttribute (Qt::AA_UseHighDpiPixmaps, true);
#endif
}
GuiApplication::~GuiApplication ()
@ -1453,6 +1447,20 @@ GuiApplication::~GuiApplication ()
shutdown ();
}
void
GuiApplication::initialize ()
{
#if QT_VERSION >= 0x040500
QCoreApplication::setAttribute (Qt::AA_DontShowIconsInMenus, false);
#endif
#if QT_VERSION >= 0x050000
QCoreApplication::setAttribute (Qt::AA_UseHighDpiPixmaps, true);
#endif
#if QT_VERSION >= 0x050600
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling, true);
#endif
}
bool
GuiApplication::notify (QObject *receiver, QEvent *e)
{

View File

@ -390,6 +390,13 @@ public:
QApplication *qapp_gui () { return this; }
/**
* @brief Does some pre-initialization
*
* Must be called before the GuiApplication object is created
*/
static void initialize ();
/**
* @brief Reimplementation of notify from QApplication
*/