Qt 获取设备屏幕大小


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();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM