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. Hiding a column in QTableView
Forum Updated to NodeBB v4.3 + New Features

Hiding a column in QTableView

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 9.3k Views 1 Watching
  • 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #2

    Do you reset the model or call insert/remove columns after hiding?

    "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
    0
    • Prince_0912P Offline
      Prince_0912P Offline
      Prince_0912
      wrote on last edited by
      #3

      Hi @gaurav118 ,
      show the code where you got problem.

      G 1 Reply Last reply
      0
      • G Offline
        G Offline
        gaurav118
        wrote on last edited by
        #4

        @VRonin I am not doing any reset or deletion of column

        1 Reply Last reply
        0
        • Prince_0912P Prince_0912

          Hi @gaurav118 ,
          show the code where you got problem.

          G Offline
          G Offline
          gaurav118
          wrote on last edited by
          #5

          @Prince_0912 here is the code snippet

          ui->tableView->setModel(_itemModel);
          populateItemModel();
          ui->tableView->setColumnHidden(1,true);

          VRoninV Prince_0912P 2 Replies Last reply
          0
          • G gaurav118

            @Prince_0912 here is the code snippet

            ui->tableView->setModel(_itemModel);
            populateItemModel();
            ui->tableView->setColumnHidden(1,true);

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

            can you show us the content of populateItemModel();?

            "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

            G 1 Reply Last reply
            0
            • G gaurav118

              @Prince_0912 here is the code snippet

              ui->tableView->setModel(_itemModel);
              populateItemModel();
              ui->tableView->setColumnHidden(1,true);

              Prince_0912P Offline
              Prince_0912P Offline
              Prince_0912
              wrote on last edited by
              #7

              @gaurav118 This code is right but in populateItemModel(); method some issue i think.

              G 1 Reply Last reply
              0
              • VRoninV VRonin

                can you show us the content of populateItemModel();?

                G Offline
                G Offline
                gaurav118
                wrote on last edited by
                #8

                @VRonin I am not maintaining that routine. populateItemModel() is filling StandardItemModel which is working fine.

                1 Reply Last reply
                0
                • Prince_0912P Prince_0912

                  @gaurav118 This code is right but in populateItemModel(); method some issue i think.

                  G Offline
                  G Offline
                  gaurav118
                  wrote on last edited by
                  #9

                  @Prince_0912 the tableView is not being reffered into that routine at all

                  Prince_0912P 1 Reply Last reply
                  0
                  • G gaurav118

                    @Prince_0912 the tableView is not being reffered into that routine at all

                    Prince_0912P Offline
                    Prince_0912P Offline
                    Prince_0912
                    wrote on last edited by
                    #10

                    @gaurav118 Your problem is like this i think,
                    https://forum.qt.io/topic/3399/solved-update-qtableview-after-hiding-columns

                    1 Reply Last reply
                    1
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #11

                      this simple example should work:

                      #include <QApplication>
                      #include <QTableView>
                      #include <QStandardItemModel>
                      int main(int argc, char *argv[])
                      {
                          QApplication application(argc, argv);
                      
                          // prepare a dummy table model
                          QStandardItemModel tableModel;
                          tableModel.insertRows(0, 5);
                          tableModel.insertColumns(0, 3);
                          for (int i = 0; i < tableModel.rowCount(); ++i) {
                              for (int j = 0; j < tableModel.columnCount(); ++j) {
                                  tableModel.setData(tableModel.index(i, j), QStringLiteral("Row: %1, Col: %2").arg(i).arg(j));
                              }
                          }
                      
                          QTableView sourceTableView;
                          sourceTableView.setModel(&tableModel);
                          sourceTableView.setColumnHidden(1,true);
                          sourceTableView.show();
                          return application.exec();
                      }
                      

                      Can you identify what that does differently from you?

                      "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
                      3

                      • Login

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