Qt 6.11 is out! See what's new in the release
blog
How to apply my own custom styling to text elements?
-
I have the following code:
Text { id: tid text: qsTr("Tid") width: parent.width //this is the part i want to style on every headline element verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter font.pixelSize: 24 }I want to repeat all of the code and use on other element like
Text { id: tid2 text: qsTr("tid2") (some kind of headline styling) }How do i make a some kind of style, that i can use repeatly on every headline element?
-
@JesperBorri Custom reusable components are quite easy to make. Just add your stylized
Textcode inside a separate QML file say for eg.MyText.qml. So now whenever you want to use this stylied custom component is another qml code, just import this file and loadMyTextcomponent inside it. All your information is contained inside this loaded component. That's it.