简体   繁体   English

模糊的 Qt 快速文本

[英]Blurred Qt Quick Text

This is an example from Qt Quick examples inside Qt Creator, when I run the project all texts lost their quality and blurred, the attached picture describes clearly the problem.这是Qt Creator中Qt Quick示例中的一个示例,当我运行该项目时,所有文本都失去了质量并变得模糊,所附图片清楚地描述了问题。

Qt Version: 5.4.1 Qt 版本:5.4.1

Platform: Windows 7平台:Windows 7

在此处输入图片说明

It is an old bug that may be reproduced on some hardware when Qt uses system OpenGL capabilities "[QTBUG-31983] Font rendering on Windows XP shows artifacts with QML Text element"这是一个旧错误,当 Qt 使用系统 OpenGL 功能时可能会在某些硬件上重现“[QTBUG-31983] Windows XP 上的字体渲染显示带有 QML 文本元素的工件”

Before Qt version 5.5 there are two types of Qt releases for Windows: ANGLE and OpenGL.在 Qt 5.5 版之前,有两种适用于 Windows 的 Qt 版本:ANGLE 和 OpenGL。 They can be distinguished by the suffix "opengl" in the installer file name, for example:它们可以通过安装程序文件名中的后缀“opengl”来区分,例如:

qt-opensource-windows-x86-msvc2013_opengl-5.4.1.exe
qt-opensource-windows-x86-msvc2013-5.4.1.exe

See "Qt 5 on Windows ANGLE and OpenGL" for the explanation.有关说明,请参阅“Windows ANGLE 和 OpenGL 上的 Qt 5”

The ANGLE build does not have such defect. ANGLE 版本没有这样的缺陷。 Only OpenGL build is affected.仅 OpenGL 构建受到影响。 OpenGL is poorly supported by default on many Windows installations.默认情况下,许多 Windows 安装对 OpenGL 的支持很差。 In some cases it can just crash during QML window initialization.在某些情况下,它可能会在 QML 窗口初始化期间崩溃。 The manual video driver installation was required.需要手动安装视频驱动程序。 However, for some old hardware it is a problem to find such good video card driver that have enough support for OpenGL.但是,对于一些老的硬件来说,要找到这么好的显卡驱动,对OpenGL有足够的支持是一个问题。

Possible solutions:可能的解决方案:

  • Use ANGLE Qt build使用 ANGLE Qt 构建
  • It is possible to subclass the standard QML Text control with default render type Text.NativeRendering :可以使用默认呈现类型Text.NativeRendering子类化标准 QML Text控件:
 Text { renderType: Text.NativeRendering; }

ANGLE Qt build could be a good solution if Windows XP should not be supported.如果不支持 Windows XP,ANGLE Qt build 可能是一个很好的解决方案。

If no intensive graphics usage is required the better solution is to use software OpenGL rendering.如果不需要密集的图形使用,更好的解决方案是使用软件 OpenGL 渲染。 Before Qt 5.4 it is was possible to use MSYS Mesa library opengl32.dll (only some specific version should be used).在 Qt 5.4 之前,可以使用 MSYS Mesa 库opengl32.dll (只应使用某些特定版本)。 If such library is placed in the executable folder of Qt application built with OpenGL Qt version, that library is automatically used for software rendering instead of default hardware rendering.如果此类库位于使用 OpenGL Qt 版本构建的 Qt 应用程序的可执行文件夹中,则该库将自动用于软件渲染,而不是默认的硬件渲染。 Starting from Qt 5.4 such library is provided by Qt: opengl32sw.dll ( http://doc.qt.io/qt-5/windows-requirements.html ).从 Qt 5.4 开始,此类库由 Qt 提供: opengl32sw.dll ( http://doc.qt.io/qt-5/windows-requirements.html )。

The software OpenGL emulation works perfectly on all types of hardware and it does not require any special video card driver.软件 OpenGL 仿真在所有类型的硬件上都能完美运行,并且不需要任何特殊的显卡驱动程序。

Starting from Qt 5.4 there is the application attribute Qt::AA_UseSoftwareOpenGL :从 Qt 5.4 开始,有应用程序属性Qt::AA_UseSoftwareOpenGL

Forces the usage of a software based OpenGL implementation on platforms that use dynamic loading of the OpenGL implementation.强制在使用 OpenGL 实现动态加载的平台上使用基于软件的 OpenGL 实现。 This will typically be a patched build of Mesa llvmpipe , providing OpenGL 2.1.这通常是Mesa llvmpipe的修补版本,提供 OpenGL 2.1。 The value may have no effect if no such OpenGL implementation is available.如果没有可用的 OpenGL 实现,则该值可能无效。 The default name of this library is opengl32sw.dll and can be overridden by setting the environment variable QT_OPENGL_DLL .这个库的默认名称是opengl32sw.dll并且可以通过设置环境变量QT_OPENGL_DLL来覆盖。 See the platform-specific pages, for instance Qt for Windows , for more information.有关更多信息,请参阅特定于平台的页面,例如Qt for Windows This value has been added in Qt 5.4.该值已在 Qt 5.4 中添加。

This happened to my QT 5.4.2 MinGW project as well.这也发生在我的 QT 5.4.2 MinGW 项目中。 Using Text.NativeRendering solved the blurry text in my case.在我的情况下,使用 Text.NativeRendering 解决了模糊的文本。

This renders the font with native rendering.这会使用本机渲染来渲染字体。 But not solves the problem with default Qt rendering.但不能解决默认 Qt 渲染的问题。

import QtQuick 2.4
import QtQuick.Window 2.0

Window {
    visible: true
    width: 512
    height: 300

    Text {
        anchors.centerIn: parent
        text: "Hello World!"
        renderType: Text.NativeRendering
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM