Setting the default color of ALL text elements



  • 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?


  • Moderators

    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.



  • You can also set this in C++. You can modify the default font of the QGuiApplication.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.