Creating an Alias for a QML Type Member
-
I was wanting to create a Button Component with a fixed background and a variable label. Something like:
@
Button {
property alias buttonLabel: styleLabel.label
style: ButtonStyle {
id: styleLabel
label: Row { }
background: Rectangle { ... }
}
}
@Is it possible to create a property alias for "label"? I can't seem to find the correct syntax to do this. Thanks!
-
What is the issue you are facing. What you are using the correct syntax.
-
bq. Is it possible to create a property alias for “label”?
I guess it won't work as the Component which it refers to would not have been initiated.
If your purpose is to dynamically change the label's component you can create a property Component and the assign it a Component when you call it.
eg:
@
MyButton.qmlItem {
property Component myComp
Button {
style: ButtonStyle {
id: styleLabel
label: myComp
background: Rectangle { ... }
}
}
}Main.qml
MyButton {
myComp: Qt.createComponent("labelDelegate1.qml")
}MyButton {
myComp: Qt.createComponent("labelDelegate2.qml")
}
@Hope this helps...