Can I globally switch to native text rendering in Qt Quick Controls 2?
Asked Answered
M

3

7

I would like to use native rendering for all the text in my application. For each Text, Label, etc. element I can do this

Text {
    renderType: Text.NativeRendering
}

to trigger native rendering. I can also use the software renderer for the whole application:

QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);

However due to some bugs with the software renderer and some performance issues, I would like to avoid that.

Is there a global switch to change the render type?

Mcconnell answered 12/4, 2017 at 12:3 Comment(0)
D
6

Since Qt 5.7, you can change the default Qt Quick text render type, but unfortunately only at build time. In order to change the default, you would have to rebuild libQt5Quick.so with QT_QUICK_DEFAULT_TEXT_RENDER_TYPE set to NativeRendering. For more details, see https://codereview.qt-project.org/#/c/121748/ .

If you have installed Qt using an installer from qt.io, install the source packages using the maintenance tool if you already haven't done so, navigate to qtdeclarative/src/quick, run qmake with the define, and build. Something along the lines:

cd path/to/Qt/Sources/5.8/qtdeclarative/src/quick
# NOTE: make sure to run qmake from the same/correct Qt installation
path/to/Qt/5.8/<spec>/qmake "DEFINES+=QT_QUICK_DEFAULT_TEXT_RENDER_TYPE=NativeRendering"
make -jN

If you have a self-built Qt installation, invoke make clean (or if you want to save time, just delete qquicktext*.o) before make to rebuild the library.

EDIT: Since Qt 5.10, it is also possible to specify the default text render type in C++ via QQuickWindow::setTextRenderType(). Just notice to set it before loading the QML content.

Deirdredeism answered 12/4, 2017 at 15:37 Comment(1)
Am I right to assume that I still need to bring in the various dependencies Qt has (install various -dev packages).Scarborough
B
6

The environment variable QML_DISABLE_DISTANCEFIELD controls this. If you put

qputenv("QML_DISABLE_DISTANCEFIELD", "1");

at the beginning of your main, you will get a nice and sharp text rendering everywhere.

Source: http://www.kdab.com/~thomas/stuff/distancefield.html

Buster answered 15/11, 2017 at 19:44 Comment(0)
H
2

Add this line first in c++ main function : QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);

Hart answered 11/7, 2020 at 12:38 Comment(2)
Thanks. Not however that this forces the software renderer.Impolite
oh! i thought you ve got an opengl driver issue , if your texts and labels render well in ur current config , why would you force to native rendering !!!Hart

© 2022 - 2024 — McMap. All rights reserved.