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. [SOLVED] ExclusiveGroup current usage
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] ExclusiveGroup current usage

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 2.5k 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.
  • L Offline
    L Offline
    literA2
    wrote on last edited by literA2
    #1

    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.

    1 Reply Last reply
    1
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      L 1 Reply Last reply
      4
      • dheerendraD dheerendra

        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 : ""
        }

        L Offline
        L Offline
        literA2
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Can you paste your CustomRadioButton code ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          L 1 Reply Last reply
          3
          • dheerendraD dheerendra

            Can you paste your CustomRadioButton code ?

            L Offline
            L Offline
            literA2
            wrote on last edited by
            #5

            @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
                }
                }
              }
            }
            
            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by dheerendra
              #6

              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
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              L 1 Reply Last reply
              4
              • dheerendraD dheerendra

                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: ""
                    }
                
                L Offline
                L Offline
                literA2
                wrote on last edited by
                #7

                @dheerendra Thank you for pointing that out!

                1 Reply Last reply
                1
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  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.

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  2

                  • Login

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