一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

QDesktopWidget这个类官方说过时了,官方强烈建议不要使用,可以用QGuiApplication代替。
先看下QDesktopWidget类获取设备信息的代码:

1 //获取设备屏幕大小
2 QDesktopWidget* desktopWidget = QApplication::desktop();
3 QRect screenRect = desktopWidget->screenGeometry();
4 qDebug()<<"screenRect"<<screenRect;

下边是QGuiApplication的方法:

头文件中:

#include <QScreen>

代码:

1 //获取设备屏幕大小
2 QRect screenRect = QGuiApplication::primaryScreen()->geometry();
3 //获取设备像素比
4 double devicePixelRatio = QGuiApplication::primaryScreen()->devicePixelRatio();
5 int screenW = screenRect.width();
6 int screenH = screenRect.height();

 

posted on 2021-05-28 08:28  一杯清酒邀明月  阅读(1660)  评论(0编辑  收藏  举报