Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Setting the default color of ALL text elements
wost last edited by
Doing some work with QML elements, and I would like every Text-element to have a default color if none is given to them. Instead of giving all Text-elements the default color of black, I would like to set a custom color. Is this possible?
I've thought about just making a custom component (with a few default properties) and replace every instance of the Text-element with this. However, there are A LOT of Text-elements and I would possibly break many components if I try to go this route.
Is there anything I can do in C++, maybe?
If you are using QtQuick.Controls (1 or 2) you can use styles to apply custom look to all components.
If you are talking about basic Text component, then there is a way: create Text.qml file (exactly the same name as the basic type), set the color there, and then make sure it's directory is imported in your other qml files. The QML engine should pick up your new implementation instead of basic type.
ibia last edited by
You can also set this in C++. You can modify the default font of the QGuiApplication.