I'm writing a Qt application that needs to run on high-dpi Windows (192dpi instead of 96dpi).
Unfortunately the Qt framework does not have support for high-dpi yet (at least on Windows), so my application and all its elements looks half the size it should.
Is there any way to force/simulate automatic upscaling of such apps by Windows?
I' am using Qt 4.8. First, you should use layouts. My goal was to prevent user to resize dialogs, forms etc. too.
I achieved correct display results on different DPI by put this code in dialog constructor:
First line
adjustSize()
adjust size of dialog to fit its content. Second linesetFixedSize(size())
fixes size of dialog after adjusting its size to content and prevent users to resize it. You haven't to set size policies.Applications that use fixed coordinates and sizes will look small on high-DPI resolutions. Although even if using layouts there are some issues regarding element and font sizes and margins. Fortunately there is support for high-DPI displays since Qt 5.4 as there has been many high-DPI issue fixes.
An application on Windows can assume one of the following levels of "DPI Awareness" (From the Qt documentation) :
Also it states that :
You can read more information here.
In general to have a good UI on high-DPI displays, consider the following :
Qt::AA_UseHighDpiPixmaps
attribute if you work withQPainter
and pixmaps, or calculate a scaling ratio for adjusting certain element sizes in special situations.Qt fully supports high DPI monitors from Qt 5.6 onward, via attribute or environment variable (except on OS X where support is native). For the attribute method, use:
or set the system environment variable:
I've tested both methods on windows 10 with a high-DPI surfacebook monitor and the results are scaled properly as expected.
Here is the quickest way to get the issue solved on Windows.
Next to the executable, create a qt.conf file (if not already there) and add the following:
The window will appear blurry when scaled up. The big advantage of this solution is that Windows does the scaling, not Qt. Therefore the occurence of artifacts is minimized. Furthermore, this can apply to an already-distributed app as it does not require a rebuild.
Of course, this is not the most pleasant result but the quickest to get you out of trouble in short term, letting you develop the "real" DPI-aware version without pressure.