[Development] Updated high-DPI support for Qt 5.14
Morten.Sorvig at qt.io
Fri Sep 13 15:43:30 CEST 2019
We’ve recently merged several patches which improves Qt’s high-DPI support. The changes include:
* Support for fractional device pixel ratios (e.g. Windows 150%)
* Support per-screen DPI in more places like QStyle
* Cleanup of configuration API and options.
These fixes applies mostly to the AA_EnableHighDpiScaling type of high-DPI support where
the device independent coordinate system is set up by QtGui. Relevant platforms include Windows,
X11, and Android. The new code and and config options are cross-platform though; it should be
possible to develop and test on any platform (as long as you are not working on platform plugins).
The following is a summary of the most relevant configuration options and API,
ignoring some of the more obscure, and now deprecated options:
* Platform plugins:
Scale factor computation has been moved to cross-platform code in order to support rounding
policy options. Platforms now provide per-screen DPI values and any natively applied scale factor:
- QPlatformScreen::logicalBaseDpi() [new] : the base DPI on the system (e.g. 96 on Windows, 72 on macOS)
- QPlatformScreen::logicalDpi() : the logical DPI of the screen (e.g. 144 on Windows 150%)
- QPlatformScreen::devicePixelRatio() : the scale factor applied by the OS/Windowing system (e.g. 1 or 2)
[QPlatformScreen::pixelDensity() will no longer be called]
* Environment variables for development and testing:
- QT_SCALE_FACTOR : enables devicePixelRatio scaling in QtGui, applies a global scale factor.
- QT_ENABLE_HIGHDPI_SCALING [new] : enables devicePixelRatio scaling in QtGui; applies per-screen
scale factors computed from on screen DPI.
- QT_FONT_DPI [now x-platform] : overrides the DPI for all screens
QT_FONT_DPI was previously x11 only, and is now cross-platform. QT_ENABLE_HIGHDPI_SCALING corresponds to
* Scale factor rounding policy
Today, Qt rounds scale factors which can result in mismatched UI sizes. We’ve now added API for setting the rounding policy:
Where the PassThrough option results in no scale factor rounding, which means that the visual UI size
will match font sizes and also the UI sizes of other applications. Note that this policy applies only when
computing a scale factor from screen DPI in QtGui; scale factors from QPlatformScreen::devicePixelRatio() or
QT_SCALE_FACTOR are used as-is.
* Manual test
This test app displays a summary of the screen/DPI/DPR configuration. Also lists relevant
No changes to Qt’s high-dpi support goes without follow-up work, so please
let me know if there are regressions, or contact me if you have questions.
More information about the Development