How to check screen dpi before a QApplication exists?
-
AA_EnableHighDpiScaling
needs to be set before a QApplication is started, but on Linux setting this property for a normal non-DPI display will cause everything to be 2x the size on Qt versions under 5.12.Thus, I need to check the screen size before setting this property, but the screen size isn't available before the application...
How can I work around this Qt bug? I support Qt 5.7+
-
Hi
I have no hires screen to test on so just asking.
You are saying that#include "mainwindow.h" #include <QApplication> #include <QScreen> int main(int argc, char *argv[]) { QApplication a(argc, argv); if ( a.screens().at(0)->geometry().width() > 2000) // 2000 is just random value. QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); else { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false ); } MainWindow w; w.show(); return a.exec(); }
Does not fix the issue , turn on/off the scaling ?
-
-
Hi
Oddly enough i installed Qt5.6 and tried on windows 10 but
didnt change the Widgets even with (Qt::AA_EnableHighDpiScaling, true);Anyway, i was wondering if a workaround would be
int main(int argc, char *argv[]) { bool EnableHighDpiScaling = false; { QApplication a(argc, argv); if ( a.screens().at(0)->geometry().width() > 1090) // check somehow. DPI i assume EnableHighDpiScaling = true; } QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, EnableHighDpiScaling); QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
It cost an extra construction of a QApplication but the added startup time should be negligible ?