[Solved]Element Template
-
Hey,
is it possible to create a Template of a QML Element or an own QML Element without using Cpp? I've got a lot of Labels and Textelements which are using a same format and it would be better to set the format once for all Labels, is that possible?
Example:
@Item {
Label {
font.size: 14
text: "Some Text"
}
Label {
font.size: 14
text: "More Text"
}
}@I would like to have it like that:
@Item {
MyLabel { // Already font size 14
text: "Some Text"
}
MyLabel { // Already font size 14
text: "More Text"
}
}@ -
Sure! All you need to do is to put your label into a new QML file and include it:
@
// MyLabel.qml
Label {
font.size: 14
}
@You need to make sure the file name (MyLabel.qml) begins with a capital letter, otherwise the QML engine will not pick it up. You include the file using standard import statement.
-
For that solution, you need a Loader or an Repeater. See the documentation.