获取当前分辨率屏幕的宽
时间: 2023-12-19 20:02:06 浏览: 137
VFP设置屏幕分辨率
3星 · 编辑精心推荐
要获取当前分辨率屏幕的宽度,可以使用Qt的QGuiApplication类和QScreen类。首先,引入以下头文件:
```
#include <QGuiApplication>
#include <QScreen>
```
然后,使用以下代码获取当前屏幕的分辨率和宽度:
```
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->geometry();
int screenWidth = screenGeometry.width();
```
这段代码中,`QGuiApplication::primaryScreen()`用于获取主屏幕,`screen->geometry()`用于获取屏幕的几何信息,`screenGeometry.width()`用于获取屏幕的宽度。将获取到的宽度赋值给`screenWidth`变量。最终,`screenWidth`就是当前分辨率屏幕的宽度。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [Qt获取屏幕分辨率](https://download.csdn.net/download/qq_35451572/10445511)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [QT分别获取当前所有屏幕的分辨率和刷新率(支持多屏)](https://download.csdn.net/download/cc279921792/13061070)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文