Qt 对高 DPI 显示器的支持

Qt 5.6 支持传统应用程序的跨平台高 DPI 缩放,类似于 macOS 本地化的缩放。

The Qt::AA_EnableHighDpiScaling application attribute, introduced in Qt 5.6, enables automatic scaling based on the monitor's pixel density.

The Qt::AA_DisableHighDpiScaling application attribute, introduced in Qt 5.6, turns off all scaling. This is intended for applications that require actual window system coordinates, regardless of environment variables. This attribute takes priority over Qt::AA_EnableHighDpiScaling.

The QT_ENABLE_HIGHDPI_SCALING environment variable, introduced in Qt 5.14, enables automatic scaling based on the pixel density of the monitor. Replaces QT_AUTO_SCREEN_SCALE_FACTOR.

The QT_SCALE_FACTOR_ROUNDING_POLICY environment variable and QGuiApplication::highDpiScaleFactorRoundingPolicy API, introduced in Qt 5.14, makes it possible to control if and how the device pixel ratio should be rounded to the nearest integer. This is relevant for configurations like Windows at 150% scale. Possible values are Round, Ceil, Floor, RoundPreferFloor, PassThrough. See the Qt::HighDpiScaleFactorRoundingPolicy enum documentation for a full description of the options. In Qt 5.4, there was an experimental implementation of high DPI scaling introduced via the QT_DEVICE_PIXEL_RATIO environment variable, that you could set to a numerical scale factor or auto. This variable was deprecated in Qt 5.6.

这允许为低 DPI 屏幕编写的应用程序在高 DPI 设备上运行不变。此功能是可选的加入,可以通过以下环境变量启用:

QT_AUTO_SCREEN_SCALE_FACTOR [boolean] 基于显示器的像素密度实现自动缩放。 这不会改变点大小字体的大小,因为点是物理单位。 多个屏幕可能会获得不同的比例因子。

QT_SCALE_FACTOR [numeric] 定义整个应用程序的全局比例因子,包括点大小的字体。【经过测试本方法十分好用】

QT_SCREEN_SCALE_FACTORS [list] 指定每个屏幕的比例因子。 这不会改变点大小字体的大小。 此环境变量主要用于调试,或者用于具有错误的 EDID information 的显示器(扩展显示标识数据)。格式可以是分号分隔的比例因子列表,它们与 QGuiApplication::screens 的顺序相同,也可以是分号分隔的 name = value 对列表,其名称与 QScreen::name 相同。

虽然 macOS 风格完全支持高 DPI,但 Windows 桌面风格目前在某些比例因素方面存在一些限制。 在这些情况下,请考虑使用 Fusion 风格,其目的是在所有情况下支持高 DPI。 注意:非整数比例因子可能会导致显着的缩放/绘画伪影。

Qt 5.6 中引入的应用程序属性 Qt :: AA_EnableHighDpiScaling 可以根据显示器的像素密度进行自动缩放。

在 Qt 5.6 中引入的应用程序属性 Qt :: AA_DisableHighDpiScaling 关闭所有缩放。 这适用于需要使用实际的窗口系统坐标的应用程序,无论环境变量如何。 此属性优先于 Qt::AA_EnableHighDpiScaling。

在 Qt 5.4 中引入了高 DPI 缩放的实验实现。 它由环境变量 QT_DEVICE_PIXEL_RATIO 启用,可以将其设置为数字比例因子或“自动”。 Qt 5.6 中不推荐使用此变量。 

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值