QDesktopWidget这个类过时了,可以用QGuiApplication
头文件#include <QScreen>
代码
//获取设备屏幕大小
QRect screenRect = QGuiApplication::primaryScreen()->geometry();
//获取设备像素比
double devicePixelRatio = QGuiApplication::primaryScreen()->devicePixelRatio();
int screenW = screenRect.width();
int screenH = screenRect.height();