Hi I have a DelegateChooser for a TableView with 10-20 different DelegateChoices. 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
Items in your example do not serve a purpose -Rectangles areItems, only colored instead of transparent, making the top levelItema duplicate. Secondly, I would just make a new fileMyBackground.qmlas such:Then you make your
ChoiceNfiles 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: