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

相关推荐
ulias2123 小时前
AVL树的实现
开发语言·数据结构·c++·windows
cn_mengbei3 小时前
鸿蒙PC开发指南:从零配置Qt环境到实战部署完整流程
qt·华为·harmonyos
山上三树3 小时前
详细介绍 C/C++ 中的内存泄漏
c语言·c++
GREGGXU3 小时前
Could not load the Qt platform plugin “xcb“ in ““ even though it was found.
linux·qt
CSDN_RTKLIB3 小时前
CMake构建目标核心命令
c++
郝学胜-神的一滴3 小时前
图形学中的纹理映射问题:摩尔纹与毛刺的深度解析
c++·程序人生·unity·游戏引擎·图形渲染·unreal engine
Cx330❀3 小时前
【优选算法必刷100题】第43题(模拟):数青蛙
c++·算法·leetcode·面试
闻缺陷则喜何志丹3 小时前
【C++动态规划 状压dp】1879. 两个数组最小的异或值之和|2145
c++·算法·动态规划·力扣·数组·最小·动态规范
艾莉丝努力练剑4 小时前
【优选算法必刷100题:专题五】(位运算算法)第033~38题:判断字符是否唯一、丢失的数字、两整数之和、只出现一次的数字 II、消失的两个数字
java·大数据·运维·c++·人工智能·算法·位运算
xiaolongmeiya4 小时前
P7082 [NWRRC 2013] Dwarf Tower 完全背包
c++