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. How can i Know SwitchDelegate is checked or not?
QtWS25 Last Chance

How can i Know SwitchDelegate is checked or not?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 296 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.
  • E Offline
    E Offline
    EmadDeve20
    wrote on last edited by
    #1

    Hello :D
    i try to create a Radio with qml UI and python backend. so for radio i had a on-off widget in this case i usingSwitchDelegate.
    so how can i know it is checked or not?

    SwitchDelegate {
                    id: switchDelegate
                    x: 195
                    y: 123
                    checked: false
                    text: qsTr("ON")
                    onCheckedChanged: {
    //                    backend.on_off_radio(parent.checked)
    
                    }
    
    1 Reply Last reply
    0
    • E Offline
      E Offline
      EmadDeve20
      wrote on last edited by
      #2

      I can print my message in onCheckedChanged so this is true.
      but i want to use a bool function if i want to test it checked is true or false how can be know?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lemons
        wrote on last edited by
        #3

        You can access the checked property directly:

        onCheckedChanged: {
                console.debug("checked value:", checked)
                if(checked)
                    console.debug("Switch is checked")
                else
                    console.debug("Switch is not checked")
            }
        

        from somewhere else you can access the property by the id of the object:

        someFunction() {
            // note you used switchDelegate as id of your SwitchDelegate
            let isSwitchChecked = switchDelegate.checked
        }
        

        or via property binding:

        SwitchDelegate {
            id: switchDelegate2
            checked: !switchDelegate.checked
        }
        
        Text {
            text: switchDelegate.checked ? "Switch is checked" : "Switch is not checked"
        }
        
        E 1 Reply Last reply
        2
        • L lemons

          You can access the checked property directly:

          onCheckedChanged: {
                  console.debug("checked value:", checked)
                  if(checked)
                      console.debug("Switch is checked")
                  else
                      console.debug("Switch is not checked")
              }
          

          from somewhere else you can access the property by the id of the object:

          someFunction() {
              // note you used switchDelegate as id of your SwitchDelegate
              let isSwitchChecked = switchDelegate.checked
          }
          

          or via property binding:

          SwitchDelegate {
              id: switchDelegate2
              checked: !switchDelegate.checked
          }
          
          Text {
              text: switchDelegate.checked ? "Switch is checked" : "Switch is not checked"
          }
          
          E Offline
          E Offline
          EmadDeve20
          wrote on last edited by
          #4

          Great @lemons this is Works :D

          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