Automatic rescaling of an application on high-dpi Windows platform?

后端 未结 5 963
轮回少年
轮回少年 2020-11-28 10:48

I\'m writing a Qt application that needs to run on high-dpi Windows (192dpi instead of 96dpi).

Unfortunately the Qt framework does not have support for high-dpi yet

5条回答
  •  無奈伤痛
    2020-11-28 11:24

    Qt fully supports high DPI monitors from Qt 5.6 onward, via attribute or environment variable (except on OS X where support is native). For the attribute method, use:

    #include 
    
    int main(int argc, char *argv[])
    {
        QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
    
        QApplication app(argc, argv);   
        return app.exec();
    }
    

    or set the system environment variable:

    QT_AUTO_SCREEN_SCALE_FACTOR=1
    

    I've tested both methods on windows 10 with a high-DPI surfacebook monitor and the results are scaled properly as expected.

提交回复
热议问题