Qt5和Qt6获取屏幕的宽高,有区别

如何获取屏幕的宽度和高度呢?

Qt5

使用QDesktopWidget这个类

cpp 复制代码
#include<QDesktopWidget>
#include<QApplication>

QDesktopWidget* desktop=QApplication::desktop();
destktop->width();
destktop->height();

Qt6

QDesktopWidget这个类在Qt6中被废弃了,使用QScreen这个类

cpp 复制代码
#include<QScreen>

QRect screen=QGuiApplication::primaryScreen()->geometry();
int w=screen.width();
int h=screen.height();

学习链接:https://github.com/0voice

相关推荐
宛 禾29 分钟前
Qt 控件入门:QLabel 从拖拽到对象树,一篇讲透
c++·qt·学习
hetao173383741 分钟前
联盟场-提高组-R7 & ZYZSC-S-Round 11
c++·算法
程序喵大人43 分钟前
【C++入门】编译链接模型 - 07 链接器怎样把符号对上号
开发语言·c++·编译器·编译链接·链接器
局部有解1 小时前
Hot100 - 三数之和
数据结构·c++·算法
longlongzihan1 小时前
C++ 常用数据结构速查:vector、stack、queue、list、树、图、哈希表等声明与核心操作
数据结构·c++·list
别动我齐刘海2 小时前
实时控制学习2
linux·c++·人工智能·学习·算法
hetao17338373 小时前
校内场-提高组 ZYZSC-S-Round 2
c++·算法
hetao17338373 小时前
2026-10-14 hetao1733837 的刷题记录
c++·算法
浅念-4 小时前
动态规划:线性DP——多状态DP与子数组专题笔记
c++·笔记·算法·leetcode·职场和发展·动态规划·力扣
打工仔折腾 AI5 小时前
Qt网络编程实战:UDP、TCP到HTTP的落地经验与选型
网络·人工智能·后端·python·qt·udp·ai agent 实战