Hi I have a DelegateChooser
for a TableView
with 10-20 different DelegateChoice
s. How can I apply the same background to all the choices? I want to avoid having to add the same background to all choices as that is a lot of repeater code and a maintenance headache:
DelegateChoice: {
Item {
Rectangle { id: background; anchors.fill: parent; color: "blue" }
Choice1 {}
}
...
Item {
Rectangle { id: background; anchors.fill: parent; color: "blue" }
Choice20 {}
}
}
First, the
Item
s in your example do not serve a purpose -Rectangle
s areItem
s, only colored instead of transparent, making the top levelItem
a duplicate. Secondly, I would just make a new fileMyBackground.qml
as such:Then you make your
ChoiceN
files inherit fromMyBackground
, for example:And your example code becomes:
Alternately, if you do not have access to your ChoiceN file contents, you can encapsulate them from outside as well: