Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52358

ButtonGroup doesn't work with a Repeater that's within a Column

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.7.0 RC
    • 5.7
    • Quick: Controls 2
    • None
    • 8f2e79776594b4466cc7766a057b5121dc0fe6ff

    Description

      Specifically, setting the first item in the repeater to be checked will fail, as the checked property will be overridden:

      import QtQuick 2.6
      import QtQuick.Window 2.2
      import Qt.labs.controls 1.0
      
      Window {
          visible: true
      
          MouseArea {
              objectName: "mouseArea"
              anchors.fill: parent
              onClicked: {
                  Qt.quit();
              }
          }
      
      
          ButtonGroup {
              objectName: "buttonGroup"
              buttons: column.children
          }
      
          Column {
              id: column
              objectName: "column"
              anchors.centerIn: parent
      
              Repeater {
                  id: repeater
                  objectName: "repeater"
                  model: ["Option 1", "Option 2", "Option 3"]
                  delegate: RadioDelegate {
                      objectName: "delegate" + index
                      checked: {
                          print("in checked assignment:", index, index == 0)
                          index == 0
                      }
                      onCheckedChanged: print("index", index, "checked", checked)
                      text: modelData
                  }
              }
          }
      }
      
      qml: in checked assignment: 0 true
      qml: index 0 checked true
      void QQuickButtonGroup::setCheckedButton(QQuickAbstractButton*) QQuickCheckDelegate(0x13761a0, name="delegate0", parent=0x13713b0, geometry=0,0 0x0)
      void QQuickButtonGroup::setCheckedButton(QQuickAbstractButton*) QQuickItem(0)
      qml: index 0 checked false
      qml: in checked assignment: 1 false
      void QQuickButtonGroup::setCheckedButton(QQuickAbstractButton*) QQuickItem(0)
      qml: in checked assignment: 2 false
      

      A workaround:

      import QtQuick 2.6
      import QtQuick.Window 2.2
      import Qt.labs.controls 1.0
      
      Window {
          visible: true
      
          MouseArea {
              objectName: "mouseArea"
              anchors.fill: parent
              onClicked: {
                  Qt.quit();
              }
          }
      
      
          ButtonGroup {
              id: bg
              objectName: "buttonGroup"
      //        buttons: column.children
          }
      
          Column {
              id: column
              objectName: "column"
              anchors.centerIn: parent
      
              Repeater {
                  id: repeater
                  objectName: "repeater"
                  model: ["Option 1", "Option 2", "Option 3"]
                  delegate: RadioDelegate {
                      objectName: "delegate" + index
                      checked: index == 0
                      text: modelData
                      ButtonGroup.group: bg
                  }
              }
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: