Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 476
Georg Schölly Avatar asked Apr 12 '17 12:04

Georg Schölly


3 Answers

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

like image 119
Jean-Michaël Celerier Avatar answered Oct 16 '22 11:10

Jean-Michaël Celerier


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.

like image 5
jpnurmi Avatar answered Oct 16 '22 11:10

jpnurmi


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

like image 2
Mamen abdou Avatar answered Oct 16 '22 11:10

Mamen abdou