Qt does support a pixel ratio (devicePixelRatio
) which is different on my various desktops:
- ) Desktop w1920 h1080 - ratio: 1
- ) Desktop w3840 h2160 with
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1")
results in Desktop w1280 h720 hi DPI ratio: 3 - ) Desktop w3840 h2160 - ratio: 1 without
QT_AUTO_SCREEN_SCALE_FACTOR
I wonder if I can manually adjust this ratio for my application, so for instance using "ratio 2" in example 2 from above.
So is there a way to set this value at runtime?
Based on http://doc.qt.io/qt-5/highdpi.html I did try something like
qputenv("QT_SCALE_FACTOR", QString::number(scaleFactor).toLocal8Bit());
Actually I did expect setting int scaleFactor = 3
would look like number 2 above, but it is not the same. Also 1-4 looks weird.
The following 3 lines look similar to qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1")
(based on https://stackoverflow.com/a/45168724/356726 )
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); //HiDPI pixmaps
qputenv("QT_SCALE_FACTOR", "1");
PS: Follow up of