High DPI Displays
High DPI Displays
High DPI monitors and displays with superb image quality and crisp font rendering are becoming increasingly popular. For example, 4K monitors may have 3840x2160 pixels, resulting in a logical resolution of 192 DPI, whereas older monitors have around 1920x1080 pixels at 96 DPI.
Issues with High DPI
High DPI Displays cause a number of issues for existing applications:
- Applications using UI designs with fixed coordinates look small. The combination of font size specification in points and other sizes in pixels is particularly problematic since points are independent of the monitor resolution. For example, a frame of 40x20 pixels around the text "hello" using a 12pt font looks correct on low resolution monitors, but the frame will be too small on high DPI monitors, causing the text to be clipped.
- Applications must adapt to situations where users have multiple displays with varying resolution. For example, they might use a 4K monitor for the document window of an image editor and a low resolution monitor for the tool box.
- Backing store and pixmap buffers become quite large so that rendering may slow down.
Operating System Support
The operating systems supported by Qt offer the following support for high DPI displays:
OS X
On OS X, there is a separate, float-based user coordinate system (as opposed to Device Pixels). For high DPI monitors, the operating system will scale the contents using an efficient scaling algorithm that will make everything look very crisp (Retina Display).
Note: The scaling is not applied to Open GL windows.
Microsoft Windows
Scaling
The user can choose a scaling factor from the control panel or via context menu. This works by making the functions for querying the system metrics return different values for standard font sizes, sizes of window borders, and so on. It does not perform any actual scaling.
DPI Awareness
An application on Windows can assume one of the following levels of "DPI Awareness":
DPI Awareness Level | Meaning |
---|---|
DPI Unaware | This level has been introduced in Windows-Vista. Windows will pretend to the application that it is running on a standard display of 96 DPI of 1920x1080 and scale the application accordingly. It is intended to accommodate older applications designed for low DPI displays. Some artifacts may result from this type of scaling. |
System-DPI Aware | This level has been introduced in Windows-Vista. It differs from Per-Monitor DPI Aware only when multiple monitors are connected. Windows will calculate a scaling suitable for all connected monitors. |
Per-Monitor DPI Aware | This level has been introduced in Windows 8.1. Windows does not perform any scaling at all. |
Qt applications by default are Per-Monitor DPI Aware on Windows 8.1 or System-DPI Aware on older versions of Windows. As of Qt 5.4, the level can be specified by passing a parameter to the platform plugin (see Using qt.conf):
<application> -platform windows:dpiawareness=0,1,2
Qt Support
- Ability to provide pixmaps or artwork for high resolution: see Drawing High Resolution Versions of Pixmaps and Images.
- Qt 5.4 introduces experimental support for scaling by by device pixel ratio similar to OS X to the platform plugins for Windows and Unix (XCB). This is controlled by the environment variable
QT_DEVICE_PIXEL_RATIO
. It can be set to a numerical value to be used as scale factor or"auto"
which causes the scale factor to be determined by checking the monitor size.It is recommended to use the
Fusion
style.
Migration of Existing Applications
In order to get an application designed for low DPI values running on a high resolution monitors quickly, consider one of the scaling options (let the application run as DPI Unaware on Windows or set the environment variable QT_DEVICE_PIXEL_RATIO
to "auto"
. These options may incur some scaling or painting artifacts, though.
In the longer term, the application should be adapted to run unmodified:
- Always use the qreal versions of the QPainter drawing API.
- Size windows and dialogs in relation to the screen size.
- Replace hard-coded sizes in layouts and drawing code by values calculated from font metrics or screen size.
Glossary Of High DPI Terms
Term | Definition |
---|---|
Device Independent Pixels | Pixels used by application (user space), subject to scaling by the operating system or Qt. |
Device Pixels | Pixels of the display device. |
Device Pixel Ratio | Scale factor applied by the operating system or Qt. |
Logical DPI | Resolution used for converting font sizes defined in points to font sizes in pixels. Typically one of the standard values 96, 128, .. 192. |
Physical DPI | Physical resolution obtained by dividing the size of the monitor by the number of pixels. |
Retina Display | See Wikipedia on Retina Displays |
User Space | The coordinate space the application uses (Device Independent Pixels). |
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.