简体   繁体   中英

improper scaling of Qt Desktop application in windows 10

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM