【Qt】解决windows高分辨和缩放问题

您所在的位置:网站首页 win7屏幕缩放比例错误怎么解决 【Qt】解决windows高分辨和缩放问题

【Qt】解决windows高分辨和缩放问题

2024-07-12 06:31| 来源: 网络整理| 查看: 265

问题

目前的工具需要适配不同分辨率以及不同缩放比例下的系统,尝试过较多的方法均不理想,后面在qt助手中找到了解决办法,

在main.cpp中添加如下代码:

QApplication::setAttribute(Qt::AA_Use96Dpi); qputenv("QT_SCALE_FACTOR", QString::number(1.0).toLatin1());

添加前

将windows的缩放设置为175%

问题:

输入框有些有变形有些文字显示不出来文字和按钮的大小不匹配 添加后

分析

Qt助手的原文:

Qt::AA_Use96Dpi

Assume the screen has a resolution of 96 DPI rather than using the OS-provided resolution. This will cause font rendering to be consistent in pixels-per-point across devices rather than defining 1 point as 1/72 inch.

将以96 DPI的分辨率显示屏幕,而不是使用操作系统提供的分辨率。这将导致字体渲染在设备上以每点像素为单位保持一致,而不是将1点定义为1/72英寸。

这个解决办法相当于是固定了设备的分辨率,牺牲了在高缩放下工具放大功能,保证的工具在不同缩放下的一致性。这应该是比较通用的解决方案,不需要重写控件的布局管理以及系统缩放等。

同时在翻看手册的时候看找到了Qt对于高分辨率的支持,如下:

Qt::AA_EnableHighDpiScaling

Enables high-DPI scaling in Qt on supported platforms (see also High DPI Displays). Supported platforms are X11, Windows and Android. Enabling makes Qt scale the main (device independent) coordinate system according to display scale factors provided by the operating system. This corresponds to setting the QT_AUTO_SCREEN​_SCALE_FACTOR environment variable to 1. This attribute must be set before QGuiApplication is constructed. This value was added in Qt 5.6.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3