#include<QScreen>
#include<QRect>
QList<QScreen *> list_screen = QGuiApplication::screens(); //多显示器
QRect rect = list_screen.at(0)->geometry();
desktop_width = rect.width();
desktop_height = rect.height();
qDebug() << desktop_width <<desktop_height;
Qt5开始,QDesktopWidget官方不建议使用,改为QScreen。
Qt5之前,使用QDesktop与desktop()函数,在Qt5中也能使用,只是官方不建议用,没有深究原因。
#include<QDesktopWidget>
QDesktopWidget *desktopwidget = QApplication::desktop(); //获取显示器分辨率
desktop_width = desktopwidget->width();
desktop_height = desktopwidget->height();