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. TableView with CheckBox in header
QtWS25 Last Chance

TableView with CheckBox in header

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmltablviewcheckbox
6 Posts 2 Posters 4.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
    PhTe
    wrote on last edited by
    #1

    Hi,
    i have a QML TableView and would like to put a checkbox in the header row.
    Therefore i added a checkbox to the headerDelegate, but if i click on it, it does not change its state. Its always 'checked'.

    Has anyone an idea why i can not click on the checkbox.
    I also tried to a add a MouseArea to the header but it seems it will be ignored as well.

    My code looks like:

    TableView {
                id: tableView
                height: parent.height
                width: parent.width/2
    
    ...
    
    headerDelegate: Item {
                    height: 20
                    anchors.left: parent.left
                    anchors.right: parent.right
    
                    CheckBox {
                        anchors.centerIn: parent
                        id: activateAllEvents
                        checked: true
                        visible: styleData.column === 4 // Show only in the 4th column
                        activeFocusOnPress: true
                        text: ""
                    }
                }
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      PhTe
      wrote on last edited by
      #2

      Has noone an idea?

      M 1 Reply Last reply
      0
      • P PhTe

        Has noone an idea?

        M Offline
        M Offline
        medyakovvit
        wrote on last edited by
        #3

        @PhTe Are some signals emitted when you click checkbox (clicked(), pressed())?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PhTe
          wrote on last edited by
          #4

          @medyakovvit No there are no signals emitted.

          I tried

          onClicked: {
              console.log("onClick");
          }
          onPressedChanged: {
              console.log("onPressedChanged");
          }
          onCheckedChanged: {
              console.log("onCheckedChanged");
          }
          

          but none of the functions are called if i click on the checkbox.

          M 1 Reply Last reply
          0
          • P PhTe

            @medyakovvit No there are no signals emitted.

            I tried

            onClicked: {
                console.log("onClick");
            }
            onPressedChanged: {
                console.log("onPressedChanged");
            }
            onCheckedChanged: {
                console.log("onCheckedChanged");
            }
            

            but none of the functions are called if i click on the checkbox.

            M Offline
            M Offline
            medyakovvit
            wrote on last edited by
            #5

            @PhTe, workaround:

            headerDelegate: Item {
                            height: 20
                            anchors.left: parent.left
                            anchors.right: parent.right
            
                            CheckBox {
                                id: activateAllEvents
                                anchors.centerIn: parent
                                
                                property bool myPressed: styleData.pressed
                                checked: true
                                visible: styleData.column === 4 // Show only in the 4th column
                                activeFocusOnPress: true
                                text: ""
                                onMyPressedChaged: {
                                    if(myPressed)
                                        checked = !checked;
                                }
                            }
                        }
            
            1 Reply Last reply
            1
            • P Offline
              P Offline
              PhTe
              wrote on last edited by
              #6

              @medyakovvit Yeah, that woks. Thanks :)

              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