Qt 5 以前:
头文件:
#include <QDesktopWidget>
#include<QApplication>
QDesktopWidget *d=QApplication::desktop();
int width=d->widht(); //屏幕的宽度
int height=d->height(); //屏幕的高度
或者简写如下:
int width=QApplication::desktop()->width();
int height=QApplication::desktop()->height();
Qt 5 之后:
头文件:
#include<QScreen>
#include<QGuiApplication>
... ... QScreen *screen=QGuiApplication::primaryScreen (); qDebug()<<screen->availableGeometry(); QRect mm=screen->availableGeometry() ; qDebug()<<mm.width ()<<mm.height ();//主屏幕分辨率的大小 ... ...