#Qt獲取屏幕分辨率 須要使用到QDesktopWidget,相關頭文件引用:code
#include <QDesktopWidget>
##單個屏幕 只獲取當前屏幕大小,較簡單:圖片
QDesktopWidget *desktop = QApplication::desktop(); Qrect screen = desktop->screenGeometry(); int screenWidth = screen.width(); int screenHeight = screen.height();
###多個屏幕 不少時候存在多個屏幕,如:存在主屏和擴展屏。則須要分別對這兩個屏幕獲取大小:文檔
QDesktopWidget *desktop = QApplication::desktop(); int screenNum = desktop->screenCount(); for (int i=0; i<screenNum; i++) { Qrect screen = desktop->screenGeometry(); qDebug("screen %d, width %d, height %d", i, screen.width(), screen.height()); }
Qt的幫助文檔提到一個問題,通常程序都但願一個窗口落在一個屏幕內, get
這須要用到:io
int primaryScreen () const
另外,提到一個虛擬桌面的概念,沒太明白是幹啥的。擴展
##參考:引用