QT6不支持QDesktopWidget包含头文件报错
QT5截屏参考:
Qt 获取设备屏幕大小
QDesktopWidget这个类官方介绍说过时了,强烈建议不要使用,可以用QGuiApplication代替。
先看下QDesktopWidget类获取设备信息的代码:
- //获取设备屏幕大小
- 2 QDesktopWidget* desktopWidget = QApplication::desktop();
- 3 QRect screenRect = desktopWidget->screenGeometry();
- 4 qDebug()<<"screenRect"<
下边是QGuiApplication的方法:
头文件中:
#include
- 1 //获取设备屏幕大小
- 2 QRect screenRect = QGuiApplication::primaryScreen()->geometry();
- 3 //获取设备像素比
- 4 double devicePixelRatio = QGuiApplication::primaryScreen()->devicePixelRatio();
- 5 int screenW = screenRect.width();
- 6 int screenH = screenRect.height();
- -----------------------------------
- Qt 获取设备屏幕大小