improper scaling of Qt Desktop application in windows 10

为君一笑 提交于 2019-12-21 12:13:49

问题


I'm writing a simple Qt (Widgets) Gui application for windows 10. I'm using the 5.6.0 beta version of Qt.

The problem I'm having is that it isn't scaling right to the screen of my surfacebook at all:

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.

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.

What's the best way to ensure that desktop, non-qml Qt applications scale properly on high-DPI monitors, specifically with windows 10?


回答1:


Qt has recently released a blog post about this issue here.

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:

  1. Set an environment variable
  2. Setting an attribute in the program source code

Setting QT_AUTO_SCREEN_SCALE_FACTOR=1 in your system environment variables will fix the scaling issue.

Additionally, setting QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); in your application source code should also allow automatic high-DPI scaling.

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();
}


来源:https://stackoverflow.com/questions/35816944/improper-scaling-of-qt-desktop-application-in-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!