[SOLVED] ExclusiveGroup current usage



  • Hi,

    I would like to ask how to use the exclusive groups's current in RadioButtons.
    I have this example:

    Item {
     property string currVal
    
     ExclusiveGroup {
        id: group
        onCurrentChanged : {
           console.log(current.value) // this returned an undefined
        }
     }
    
     CustomRadioButton {
            id: topButton
            text: qsTr("Top")
            checked: true
            exclusiveGroup: group
            value: "top"
        }
        CustomRadioButton {
            id: bottomButton
            text: qsTr("Bottom")
            exclusiveGroup: group
            value: "bottom"
        }
     }
    

    Question: How can i get the value of the current object in ExclusiveGroup?

    Am I doing wrong? Please advise. Thanks.



  • what you are doing is correct. Can you paste your CustomRadioButton ?
    Hope you have done something like the following in CustomRadioButton.qml

    RadioButton {
    property string value : ""
    }



  • @dheerendra Thanks for the reply.

    Yes, I have set a property value on my CustomRadioButton.

    But the problem is on the log, it says undefined.



  • Can you paste your CustomRadioButton code ?



  • @dheerendra here it is:

    Item {
      id: radioItem
      property alias exclusiveGroup: radioButton.exclusiveGroup
      property alias checked: radioButton.checked;
      property alias text: text.text;
      property alias info: infoText.text;
      property string value: ""
    
      implicitHeight: Math.max(text.implicitHeight, labelColumn.implicitHeight)
      implicitWidth: parent.width
    
      RowLayout {
       id: layout
       anchors {
        top: parent.top
        left: parent.left
        right: parent.right
      }
    
      RadioButton {
        id: radioButton
        Layout.alignment: Qt.AlignTop
        style: ControlStyles.RadioButtonStyle {
          indicator: Image {
            readonly property string over: radioButton.pressed ? "-over" : ""
            readonly property string onOff: radioButton.checked ? "on" : "off"
    
            source: StaticData.getImage("radio-" + onOff + (radioButton.enabled ? over : "-disabled" ) + ".png")
          }
        }
      }
    
      ColumnLayout {
        id: labelColumn
        Layout.fillWidth: true
        Layout.alignment: Qt.AlignTop
    
        Text {
          id: text
          Layout.fillWidth: true
         horizontalAlignment: Text.AlignLeft
          wrapMode: Text.WordWrap
        }
    
        Text {
          id: infoText
          Layout.fillWidth: true
          horizontalAlignment: Text.AlignLeft
          wrapMode: Text.WordWrap
        }
        }
      }
    }


  • Two things.

    1. Your CustomRadioButton is not a RadioButton. It contains the radioButton.
    2. 'current' object in signal is RadioButton and not the your top level object of type CustomRadioButton.
    3. Property 'value' is not in RadioButton object. Hence the error.

    You should move the property string value to RadioButton mentioned in customComponent.

    Replace you value property like this in Item.
    property alias value : radioButton.value

    Make your RadioButton like this.

        RadioButton {
            id: radioButton
            Layout.alignment: Qt.AlignTop
            objectName: "Dheeru"
            property string value: ""
        }


  • @dheerendra Thank you for pointing that out!



  • Cool. Hope this helped. You can move this question to SOLVED state. Also up-vote my answer if it has helped you to solve the problem.

    Happy Qt/QML Programming.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.