如何使用Qt 5.6在高dpi上获得清晰的UI? [英] How to get sharp UI on high dpi with Qt 5.6?

查看:94
本文介绍了如何使用Qt 5.6在高dpi上获得清晰的UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用4k显示器进行开发,这很痛苦...

I am developing on a 4k monitor and its a pain...

最后我设法设置了QtDesigner,然后遇到了这个问题:

Finally I managed to set up QtDesigner and then ecountered this issue:

当您使用 QT_AUTO_SCREEN_SCALE_FACTOR = 1 并使用单选按钮和其他基本小部件编译应用程序时,它看起来会在4k屏幕上缩放.否则,控件的尺寸是正确的,并且符合预期,只是不清晰,而是像素化.

When you use QT_AUTO_SCREEN_SCALE_FACTOR=1 and compile an app with radiobutton and other basic widgets, it looks scaled on a 4k screen. Otherwise the dimensions of controls are correct and as expected, its just not sharp, but rather pixelated.

我使用Qt 5.6 RC msvc2015 64bit在4k屏幕上以200%DPI缩放在Windows 10 Home 64bit上运行,并尝试使用

I am running on Windows 10 Home 64bit on 4k screen with 200% DPI zoom, using Qt 5.6 RC msvc2015 64bit and tried with achieving the same results using

QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

如果我使用

QGuiApplication::setAttribute(Qt::AA_DisableHighDpiScaling);

控件很锐利,文本大小还可以,但所有尺寸都小得多.

the controls are sharp, text size is ok BUT all dimensions are much smaller.

如何在高DPI屏幕上使控件清晰?

How do I make controls sharp on high DPI screen?

推荐答案

如Qt文档所述:

Use QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors.
QT_SCREEN_SCALE_FACTORS to set per-screen factors.
QT_SCALE_FACTOR to set the application global scale factor.

您可以尝试做Qt Creator正在做的事情:

You can try doing what Qt Creator is doing:

static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
        && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
        && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
        && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
}

最重要的是最后一行 QCoreApplication :: setAttribute(Qt :: AA_EnableHighDpiScaling); .

这篇关于如何使用Qt 5.6在高dpi上获得清晰的UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆