Qt6 topics merged with General

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 {
    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 {
    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?


  • Moderators


    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.

  • Hi,

    yes.. i thought i might can avoid executable code in the qml file. I gonna try it soon. Thank you for your reply!

Log in to reply