Qt5獲取屏幕分辨率

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章