Windows 10中Qt Desktop应用程序的缩放比例不正确 [英] improper scaling of Qt Desktop application in windows 10
问题描述
我正在为Windows 10编写一个简单的Qt(窗口小部件)Gui应用程序.我正在使用Qt的5.6.0 beta版.
I'm writing a simple Qt (Widgets) Gui application for windows 10. I'm using the 5.6.0 beta version of Qt.
我遇到的问题是它根本无法缩放到我的Surfacebook的屏幕上:
The problem I'm having is that it isn't scaling right to the screen of my surfacebook at all:
很难说出来,因为SO会缩放图像,但是请注意,停靠窗口小部件标题栏控件相对于窗口标题栏控件的大小.
It's a bit hard to tell because SO scales the image, but notice how small the dock widget title bar controls are relative to the window title bar controls.
此链接讨论了缩放,但主要集中在qml/qtQuick和移动应用程序,通常还暗示,在台式机QtWidgets应用程序中,QPainter
将自动确定适当的缩放比例,而显然不是.
This link from Qt talks about scaling, but it's mostly focuses on qml/qtQuick and mobile applications in general, and additionally seems to imply that in a desktop QtWidgets application, QPainter
will automatically determine the proper scaling, which it clearly is not.
确保台式机,非qml Qt应用程序在高DPI显示器(尤其是Windows 10)上正确缩放的最佳方法是什么?
What's the best way to ensure that desktop, non-qml Qt applications scale properly on high-DPI monitors, specifically with windows 10?
推荐答案
Qt has recently released a blog post about this issue here.
从Qt 5.6起启用了高DPI支持.在OS X平台上,本机支持High-DPI.在X11/Windows/Android上,有两种方法可以根据博客文章启用高DPI检测:
High DPI support is enabled from Qt 5.6 onward. On OS X platforms, there is native support for High-DPI. On X11/Windows/Android, there are two methods to enable high-DPI detection per the blog post:
- 设置环境变量
- 在程序源代码中设置属性
在系统环境变量中设置QT_AUTO_SCREEN_SCALE_FACTOR=1
将解决扩展问题.
Setting QT_AUTO_SCREEN_SCALE_FACTOR=1
in your system environment variables will fix the scaling issue.
此外,在应用程序源代码中设置QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
还应该允许自动进行高DPI缩放.
Additionally, setting QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
in your application source code should also allow automatic high-DPI scaling.
注意:要使用属性方法,必须 在创建QApplication
对象之前先设置属性 ,也就是说:
NOTICE: To use the attribute method, you must set the attribute before you create your QApplication
object, that is to say:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
return app.exec();
}
这篇关于Windows 10中Qt Desktop应用程序的缩放比例不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!