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