在高 dpi Windows 平台上自动重新缩放应用程序? [英] Automatic rescaling of an application on high-dpi Windows platform?
问题描述
我正在编写一个需要在高 dpi Windows(192dpi 而不是 96dpi)上运行的 Qt 应用程序.
I'm writing a Qt application that needs to run on high-dpi Windows (192dpi instead of 96dpi).
不幸的是,Qt 框架还不支持高 dpi(至少在 Windows 上),所以我的应用程序及其所有元素看起来只有它应该大小的一半.
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.
有没有办法强制/模拟 Windows 对此类应用程序的自动升级?
Is there any way to force/simulate automatic upscaling of such apps by Windows?
推荐答案
使用固定坐标和大小的应用程序在高 DPI 分辨率下看起来很小.尽管即使使用布局也存在一些关于元素和字体大小和边距的问题.幸运的是,从 Qt 5.4 开始就支持高 DPI 显示,因为已经有许多 高 DPI 问题修复.
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.
Windows 上的应用程序可以采用以下DPI Awareness"级别之一(来自 Qt 文档):
An application on Windows can assume one of the following levels of "DPI Awareness" (From the Qt documentation) :
- DPI Unaware:此级别已在 Windows-Vista 中引入.Windows 会假装应用程序正在运行1920x1080 的 96 DPI 标准显示和缩放应用程序因此.它旨在容纳设计的较旧的应用程序用于低 DPI 显示器.某些工件可能是由这种类型的缩放.
- 系统-DPI 感知:此级别已在 Windows-Vista 中引入.它与 Per-Monitor DPI Aware 不同,仅当多个显示器连接的.Windows 将计算适合所有连接的缩放比例监视器.
- 每显示器 DPI 感知:此级别已在 Windows 8.1 中引入.Windows 根本不执行任何缩放.
它还指出:
默认情况下,Qt 应用程序在 Windows 8.1 或旧版 Windows 上的系统 DPI 感知.从 Qt 5.4 开始,级别可以通过将参数传递给平台插件来指定(请参阅使用 qt.conf):
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
您可以在此处阅读更多信息.
You can read more information here.
一般来说,要在高 DPI 显示器上拥有良好的用户界面,请考虑以下事项:
In general to have a good UI on high-DPI displays, consider the following :
- 使用最新版本的 Qt
- 使用布局并避免固定尺寸(除非您自己计算缩放比例)
- 根据您的应用程序需要进行适当的 DPI 相关设置,例如,如果您使用
QPainter
和像素图,则设置Qt::AA_UseHighDpiPixmaps
属性,或计算缩放比例用于在特殊情况下调整某些元素大小.
- Use the latest version of Qt
- Use layouts and avoid fixed sizes (unless you calculate scaling ratios on your own)
- Make appropriate DPI-related settings depending on your application needs, for example set
Qt::AA_UseHighDpiPixmaps
attribute if you work withQPainter
and pixmaps, or calculate a scaling ratio for adjusting certain element sizes in special situations.
这篇关于在高 dpi Windows 平台上自动重新缩放应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!