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. Check/UnCheck all checkbox in QTableView
QtWS25 Last Chance

Check/UnCheck all checkbox in QTableView

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.8k 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.
  • Q Offline
    Q Offline
    Qt-Developer
    wrote on last edited by
    #1

    Dear Friends, I am a new developer, learning qt. I would like to know is it possible to add a check box column in QTableView column and to use a check box in the column header. From the column header checkbox can we check/uncheck the column checkboxes. Can anyone please provide a solution how can we achieve this.

    JonBJ VRoninV 2 Replies Last reply
    0
    • Q Qt-Developer

      Dear Friends, I am a new developer, learning qt. I would like to know is it possible to add a check box column in QTableView column and to use a check box in the column header. From the column header checkbox can we check/uncheck the column checkboxes. Can anyone please provide a solution how can we achieve this.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Qt-Developer
      What about https://wiki.qt.io/Technical_FAQ#How_can_I_insert_a_checkbox_into_the_header_of_my_view.3F ?

      1 Reply Last reply
      1
      • Q Qt-Developer

        Dear Friends, I am a new developer, learning qt. I would like to know is it possible to add a check box column in QTableView column and to use a check box in the column header. From the column header checkbox can we check/uncheck the column checkboxes. Can anyone please provide a solution how can we achieve this.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        @Qt-Developer said in Check/UnCheck all checkbox in QTableView:

        is it possible to add a check box column in QTableView

        The view does not control the contents of the table, the model does. anyway it's possible:

            QStandardItemModel model;
            model.insertColumns(0,3);
            model.insertRows(0,3);
            for(int i=0;i<3;++i){
               model.setData(model.index(i,0),QStringLiteral("foo"));
               model.setData(model.index(i,1),QStringLiteral("bar"));
               model.setData(model.index(i,2),QStringLiteral("foobar"));
               model.setData(model.index(i,0),Qt::Unchecked,Qt::CheckStateRole); // displays the checkbox
               model.item(i,0)->setFlags(model.flags(model.index(i,0)) | Qt::ItemIsUserCheckable); // allows the user to interact with the checkbox
            }
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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