Radiobuttons in listview and groups by sections
-
Hi,
Im trying to build a listview containing radiobuttons. The listview has sections as described above in the code.
@Rectangle {
ListModel {
id:nameModel
ListElement {name: "Grey"; sectionName: "apples" }
ListElement {name: "Red"; sectionName: "apples" }
ListElement {name: "Blue"; sectionName: "cars"}
ListElement {name: "Green";sectionName: "cars"}
}
ListView {
anchors.fill: parent
model: nameModel
delegate {
RowLayout{
RadioButton{
text: "test"
exclusiveGroup: sectionName
}
Text {
text: name;
font.pixelSize: 24
}
}
}
section {
property: "sectionName"
delegate: Rectangle {
width: parent.width
height: childrenRect.height + 4
Text {
font.pixelSize: 16
font.bold: true
text: section} } } }
}@
Now I would like the RadioButtons of each section to be exclusive. It would be so nice if I could convert the section string into an exclusiveGroup but i didnt find a way to do this. Do you have any ideas?
greetings
Pioupus -
Hi,
One way would be to iterate over the List on each RadioButton click and check if its present in that Group (i.e section) and set it checked while the rest should be unchecked. You can obtain the Section from the ListModel.