问题
I am developing on a 4k monitor and its a pain...
Finally I managed to set up QtDesigner and then ecountered this issue:
When you use QT_AUTO_SCREEN_SCALE_FACTOR=1
and compile an app with radiobutton and other basic widgets, it looks scaled on a 4k screen.
Otherwise the dimensions of controls are correct and as expected, its just not sharp, but rather pixelated.
I am running on Windows 10 Home 64bit on 4k screen with 200% DPI zoom, using Qt 5.6 RC msvc2015 64bit and tried with achieving the same results using
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
If I use
QGuiApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
the controls are sharp, text size is ok BUT all dimensions are much smaller.
How do I make controls sharp on high DPI screen?
回答1:
As Qt documentation says:
Use QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors.
QT_SCREEN_SCALE_FACTORS to set per-screen factors.
QT_SCALE_FACTOR to set the application global scale factor.
You can try doing what Qt Creator is doing:
static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
&& !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
&& !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
&& !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}
Basically important thing is the last line QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
.
回答2:
With QT_AUTO_SCREEN_SCALE_FACTOR, the point size of the fonts are not changed, they're just scaled up from their original pixels, so they will never be smooth, only more bumpy.
Ref: http://doc.qt.io/qt-5.6/highdpi.html#high-dpi-support-in-qt "This will not change the size of point sized fonts"
You need to use QT_SCALE_FACTOR instead to rescale your app, not just rescale its pixels.
来源:https://stackoverflow.com/questions/35714837/how-to-get-sharp-ui-on-high-dpi-with-qt-5-6