QT 多显示屏获取屏幕分辨率

如果只有一个显示器使用

QApplication::desktop()->width();
QApplication::desktop()->height();

就可以获取到屏幕分辨率。

但是如果是多个显示屏的扩展屏,这样获取到的就是总的屏幕尺寸。

而screenGeometry()所属的类QDesktopWidget在逐步淘汰中,使用了会有警告。

不过如果想要获取单一显示屏的屏幕尺寸,可以使用:
 


    QList<QScreen *> screenList = QGuiApplication::screens();
    QScreen *mScreen = screenList.first();//第一个屏幕,其他依次类推
    QRect screenRect = mScreen->geometry();
    double screen_width = screenRect.width();
    double screen_height = screenRect.height();

猜你喜欢

转载自blog.csdn.net/hss2799/article/details/110420371