QT 设置高DIP支持多分屏幕,window缩放比例问题等

时间:2024-11-26 11:22:11

一.高清屏支持

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#endif

二.设置window系统缩放比例120%后,软件窗口不适应的问题。 

        QGuiApplication::primaryScreen();    

        得到window的缩放比:dp = screen->devicePixelRatio();

        在resize(width* dp, height * dp);