Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Radiobuttons in listview and groups by sections

Radiobuttons in listview and groups by sections

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pioupus
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pioupus
        wrote on last edited by
        #3

        Hi,

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved