Qt does support a pixel ratio (devicePixelRatio) which is different on my various desktops:
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1") results in Desktop w1280 h720 hi DPI ratio: 3QT_AUTO_SCREEN_SCALE_FACTORI 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
This is my current workaround as I was asked. It only works if I do it before I construct the UI, so I call it at the beginning.
Passing values around 1.0 (e.g 0.75) work on high DPI screens. But I cannot change it later.
void CGuiApplication::highDpiScreenSupport(double scaleFactor)
{
if (scaleFactor < 0)
{
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
}
else
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); // HiDPI pixmaps
const QString sf = QString::number(scaleFactor, 'f', 2);
qputenv("QT_SCALE_FACTOR", sf.toLatin1());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With