Windows上的QT高DPI支持 [英] QT High DPI Support on Windows

查看:751
本文介绍了Windows上的QT高DPI支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此处的文档 http://doc.qt.io/qt-5/highdpi.html QT 5.4+引入了对DPI的高度支持. 但是,或者我缺少基本的东西,或者当前的支持还处于非常早期的阶段. 我正在编写一个全新的应用程序,因此我有机会从头开始做.我知道我必须使用布局而不是固定的位置等,但是在某些情况下,我总是必须指定控件的最小/最大尺寸.我可以在编辑器中指定它们,但是这些是设备像素.因此,如果我将Windows设置更改为使用150%DPI,则编辑器中的最小值/最大值将太小.当然,我可以获取该比率并在代码中调整所有必需的值,但是如果我必须手动完成所有操作,那么QT为我提供了什么样的高DPI支持?我的意思是与QT 5.4之前的版本有什么不同?

According to documentation here http://doc.qt.io/qt-5/highdpi.html QT 5.4+ introduces high DPI support. However, either I’m missing something fundamental or the current support is still in very early stages. I’m writing a brand new application so I have a chance to do it right from the ground up. I understand that I would have to use layouts instead of fixed positioning etc, but there always going to be cases in which I would have to specify, for example a minimum/maximum size of a control. I can specify them in the editor, but these are device pixels. So if I change my Windows settings to use 150% DPI then min/max values in the editor would be too small. Of course I can obtain that ratio and adjust all the required values in code, but then what kind of high DPI support does QT give for me if I have to do everything by hand? I mean how is it different to pre QT 5.4?

然后一个有趣的是QT_DEVICE_PIXEL_RATIO环境变量.它完全满足我的需要,它将编辑器中设置的所有像素乘以一个因子.但是,为什么它是环境变量而不是每个应用程序设置?既然我们知道Windows具有125、150%等设置,为什么它只支持2、3等整数值?为什么它不能自动读取Windows设置并将其自身设置为该值?

Then an interesting one is QT_DEVICE_PIXEL_RATIO environment variable. It does exactly what I need, it multiplies all pixels set in editor by a factor. But why is it an environment variable and not a per application setting? Why does it only support integer values of 2, 3 etc, since we know that Windows has settings like 125, 150% etc. and why couldn’t it automatically read the Windows setting and set itself to that value?

推荐答案

我必须回复@Nicolas Holthaus的回答,即启用Qt :: AA_EnableHighDpiScaling的方式可能并非绝对正确.因为它将四舍五入用户DPI设置.例如. Windows DPI设置为150%,字体和大小的结果为200%,而125%为100%.

I must response the answer from @Nicolas Holthaus that the way you enable Qt::AA_EnableHighDpiScaling may not be absolutely right. Since it will round the user DPI setting. Eg. Windows DPI setting be 150%, the result will be 200% for font and size, while 125% will be 100%.

设置正确的DPI缩放比例的正确方法是设置环境变量QT_SCALE_FACTOR.对于同一示例,如果DPI设置为150%,则将QT_SCALE_FACTOR设置为值1.5.那么结果将是字体和大小恰好为150%.

The right way to do correct DPI scaling is set environment variable QT_SCALE_FACTOR. For the same example, if DPI setting is 150%, set QT_SCALE_FACTOR with value 1.5. Then the result will be exactly 150% in font and size.

请参阅qt官方文档 http://doc.qt.io/qt-5/highdpi.html ,您会找到

See the qt official document http://doc.qt.io/qt-5/highdpi.html and you will find

QT_SCALE_FACTOR [numeric] defines a global scale factor for the whole application, including point sized fonts.

这篇关于Windows上的QT高DPI支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆