Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How To Add Select All Checkbox in QTableWidget QHeaderView

How To Add Select All Checkbox in QTableWidget QHeaderView

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetqheaderviewcheckboxselect all
3 Posts 2 Posters 12.7k 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.
  • M Offline
    M Offline
    maximo
    wrote on 22 Oct 2015, 06:24 last edited by maximo
    #1

    Is there a way to add a "Select All Checkbox" to a QTableWidget in the first header column? I mean, I found that I can add checkboxes on rows beneath the header, just not a checkbox in the header itself.

    I tried the following, but it shows no change:

    // item(0,0) is a cell with a checkbox in it (first row after the header, first column)
    QTableWidgetItem *oItem = ui->myTable->item(0,0)->clone();
    oItem->setCheckState(Qt::Unchecked);
    ui->myTable->setHorizontalHeaderItem(0,oItem);
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximo
      wrote on 22 Oct 2015, 08:03 last edited by
      #2

      The answer is in the Qt FAQ:

      https://wiki.qt.io/Qt_project_org_faq#How_can_I_insert_a_checkbox_into_the_header_of_my_view.3F

      I found that this also worked using an existing QTableWidget that was drawn on the page, like so:

      MyHeader *myHeader = new MyHeader(Qt::Horizontal, ui->myTable);
      ui->myTable->setHorizontalHeader(myHeader);
      

      And even though it does setHorizontalHeader and looks like it might replace your existing header, it appears to only affect the first header column.

      M 1 Reply Last reply 22 Oct 2015, 08:09
      0
      • M maximo
        22 Oct 2015, 08:03

        The answer is in the Qt FAQ:

        https://wiki.qt.io/Qt_project_org_faq#How_can_I_insert_a_checkbox_into_the_header_of_my_view.3F

        I found that this also worked using an existing QTableWidget that was drawn on the page, like so:

        MyHeader *myHeader = new MyHeader(Qt::Horizontal, ui->myTable);
        ui->myTable->setHorizontalHeader(myHeader);
        

        And even though it does setHorizontalHeader and looks like it might replace your existing header, it appears to only affect the first header column.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 22 Oct 2015, 08:09 last edited by mrjj
        #3

        @maximo
        Hi
        It creates a new Header that draws a check box image on itself since its not possible to insert a real widget.
        It then response to mouse press to make the image work as a real check box.

        it checks with
        if (logicalIndex == 0)

        so I think it only paints this in first column.

        1 Reply Last reply
        0

        3/3

        22 Oct 2015, 08:09

        • Login

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