How to apply my own custom styling to text elements?
Solved
QML and Qt Quick
-
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
Text
code 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 loadMyText
component inside it. All your information is contained inside this loaded component. That's it.