High DPI Displays▲
High DPI displays have increased pixel density, compared to standard DPI displays.
Pixel density is measured in Dots per Inch (DPI) or Pixels per Inch (PPI), and is determined by the number of display pixels and their size. Consequently, the number of pixels alone isn't enough to determine if a display falls into the high-DPI category.
A 4K monitor has a fixed number of pixels (~8M), however its DPI varies between 185 (23 inches) and 110 (40 inches). The former is around twice the standard 96 DPI desktop resolution; the latter barely exceeds this resolution.
Challenges with High DPI▲
High DPI displays bring about some challenges for existing applications:
-
Applications using UI designs with fixed coordinates look small The combination of specifying font size in points and other sizes in pixels is particularly problematic because points are independent from the monitor's resolution. For example, suppose we have a frame of 40x20 pixels around the text "hello". If we use a 12pt font, it would look correct on low resolution monitors. But, on high DPI monitors, the frame would be too small, resulting in the text being clipped.
-
Applications must adapt to situations where users have multiple displays with varying resolutions For example, a user might use a 4K monitor for the document window of an image editor but a low resolution monitor for the tool box.
Traditionally, to support high DPI, Qt scales fonts automatically and provides a DPI value that application code can use to scale the rest of the UI.
High DPI Support on a System Level▲
Qt supports a high DPI mode where the main coordinate system is virtualized and made independent from the display pixel density. Some operating systems, like macOS and iOS implement this mode. Additionally, if an operating system doesn't support this mode, Qt has an implementation to fallback on.
Now, geometry is specified in device independent pixels. This includes widget and item geometry, event geometry, desktop, window and screen geometry, as well as animation velocities. The output is rendered in device pixels, which corresponds to the display resolution. The devicePixelRatio is the ratio between the device independent pixels and the device pixel coordinate system.
Typically, most applications work with device independent pixels; except for OpenGL and code for raster graphics.
Operating System Support▲
The Qt-supported operating systems offer the following for high DPI displays:
macOS and iOS▲
The Apple platforms implement scaling and coordinate system virtualization in the operating system. Normally, no special configuration is required.
On macOS, high-DPI support is enabled by settings in the Info.plist file; so make sure these settings are present.
&
lt;key&
gt;NSPrincipalClass&
lt;/
key&
gt;
&
lt;string&
gt;NSApplication&
lt;/
string&
gt;
&
lt;key&
gt;NSHighResolutionCapable&
lt;/
key&
gt;
&
lt;string&
gt;True&
lt;/
string&
gt;
Newer versions of qmake will generate an Info.plist file with the NSPrincipalClass key; this is sufficient since NSHighResolutionCapable is true by default.
Both macOS and iOS may apply further virtualization, such that device pixels no longer correspond to display pixels 1:1. This happens on the iPhone 6+ and on macOS configured with "display scaling" enabled.
Microsoft Windows▲
Scaling
Users choose a scaling factor from the Control Panel or via the 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 doesn't 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 was introduced in Windows Vista. To the application, Windows pretends as if it's running on a standard display of 96 DPI of 1920x1080 and scales the application accordingly. It's intended to accommodate older applications designed for low DPI displays. This type of scaling may result in some artifacts. |
System-DPI Aware |
This level was introduced in Windows Vista. It differs from Per-Monitor DPI Aware only when multiple monitors are connected. Windows calculates a scaling that's suitable for all monitors connected. |
Per-Monitor DPI Aware |
This level was introduced in Windows 8.1. Windows does not perform any scaling at all. |
By default, Qt applications are set to Per-Monitor DPI Aware on Windows 8.1 or System-DPI Aware on older Windows versions. As of Qt 5.4, this level can be specified via a parameter to the platform plugin:
&
lt;application&
gt; -
platform windows:dpiaware