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. Add form widget in QTableview using model view
Forum Updated to NodeBB v4.3 + New Features

Add form widget in QTableview using model view

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 4.1k Views 3 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 26 Jun 2018, 20:07 last edited by
    #7

    The QTableView shows what the model has to give. If the model says 8 column then the table view will show 8.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    J 1 Reply Last reply 27 Jun 2018, 05:07
    1
    • S SGaist
      26 Jun 2018, 20:07

      The QTableView shows what the model has to give. If the model says 8 column then the table view will show 8.

      J Offline
      J Offline
      JadeN001
      wrote on 27 Jun 2018, 05:07 last edited by JadeN001
      #8

      @SGaist okay It means I have to manage model.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JadeN001
        wrote on 27 Jun 2018, 10:57 last edited by
        #9

        In my code i have used insertrow() in my QStandardItemModel.

        void MainWindow::seteditor()
        {
        
           model=new QStandardItemModel(this);
        
            QStandardItem *item=new QStandardItem(" ");
            ui->tableView->setModel(model);
        
              for(int row=0;row<4;++row)
              {
                   model->insertRow(row,item);
                   QModelIndex index= model->index(row,1,QModelIndex());
                 ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
                ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
                   ui->tableView->setItemDelegate(D);
                   ui->tableView->openPersistentEditor(index);  '<- not working'
        
        
              }
        
        
        
                }
        

        however if I use :

           model=new QStandardItemModel(8,2,this);
        
        

        instead of

           model=new QStandardItemModel(this);
        
        

        It works properly.But I want to use first approach.Where I am doing mistake?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 Jun 2018, 16:23 last edited by
          #10

          Hi
          You mean like
          model=new QStandardItemModel(this);
          model->setRowCount(8):
          model->setColumnCount(2):

          J 1 Reply Last reply 28 Jun 2018, 04:41
          1
          • M mrjj
            27 Jun 2018, 16:23

            Hi
            You mean like
            model=new QStandardItemModel(this);
            model->setRowCount(8):
            model->setColumnCount(2):

            J Offline
            J Offline
            JadeN001
            wrote on 28 Jun 2018, 04:41 last edited by
            #11

            @mrjj I want to increase number of cells based on client connection.So for that i have to use counter for generating rows and columns.

            It is helpful to use
            model=new QStandardItemModel(this);
            model->setRowCount(8):
            model->setColumnCount(2):
            Instead of model=new QStandardItemModel(8,2,this); so that i can set rows and column based on requirments.

            I am on right track or not i don't.suggest me if there is ant better way for my scenario.

            M 1 Reply Last reply 28 Jun 2018, 06:17
            0
            • J JadeN001
              28 Jun 2018, 04:41

              @mrjj I want to increase number of cells based on client connection.So for that i have to use counter for generating rows and columns.

              It is helpful to use
              model=new QStandardItemModel(this);
              model->setRowCount(8):
              model->setColumnCount(2):
              Instead of model=new QStandardItemModel(8,2,this); so that i can set rows and column based on requirments.

              I am on right track or not i don't.suggest me if there is ant better way for my scenario.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 28 Jun 2018, 06:17 last edited by
              #12

              @JadeN001
              Hi
              you should test if
              void QStandardItemModel::appendRow(const QList<QStandardItem *> & items)
              does not auto increase row count also.

              J 1 Reply Last reply 29 Jun 2018, 10:22
              1
              • M mrjj
                28 Jun 2018, 06:17

                @JadeN001
                Hi
                you should test if
                void QStandardItemModel::appendRow(const QList<QStandardItem *> & items)
                does not auto increase row count also.

                J Offline
                J Offline
                JadeN001
                wrote on 29 Jun 2018, 10:22 last edited by JadeN001
                #13

                @mrjj thanks..
                It does not auto increase row count

                M 1 Reply Last reply 29 Jun 2018, 10:49
                1
                • J JadeN001
                  29 Jun 2018, 10:22

                  @mrjj thanks..
                  It does not auto increase row count

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 29 Jun 2018, 10:49 last edited by
                  #14

                  @JadeN001
                  ok, so u have to manage that yourself

                  J 1 Reply Last reply 29 Jun 2018, 11:51
                  0
                  • M mrjj
                    29 Jun 2018, 10:49

                    @JadeN001
                    ok, so u have to manage that yourself

                    J Offline
                    J Offline
                    JonB
                    wrote on 29 Jun 2018, 11:51 last edited by
                    #15

                    @mrjj , @JadeN001

                    It does not auto increase row count

                    You guys are claiming that QStandardItemModel::rowCount() remains unchanged after QStandardItemModel::appendRow()? Surely something is wrong here....?

                    M 1 Reply Last reply 29 Jun 2018, 16:10
                    2
                    • J JonB
                      29 Jun 2018, 11:51

                      @mrjj , @JadeN001

                      It does not auto increase row count

                      You guys are claiming that QStandardItemModel::rowCount() remains unchanged after QStandardItemModel::appendRow()? Surely something is wrong here....?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 29 Jun 2018, 16:10 last edited by
                      #16

                      @JonB
                      Nope, i said check it as it really sound it would. ( append in name)
                      But docs says
                      "Appends a row containing items. If necessary, the column count is increased to the size of items."
                      And no mention of rowCount.
                      But i really suspect it would so if you says it does, i believe you over the docs.

                      J 1 Reply Last reply 29 Jun 2018, 17:40
                      0
                      • M mrjj
                        29 Jun 2018, 16:10

                        @JonB
                        Nope, i said check it as it really sound it would. ( append in name)
                        But docs says
                        "Appends a row containing items. If necessary, the column count is increased to the size of items."
                        And no mention of rowCount.
                        But i really suspect it would so if you says it does, i believe you over the docs.

                        J Offline
                        J Offline
                        JonB
                        wrote on 29 Jun 2018, 17:40 last edited by
                        #17

                        @mrjj

                        "Appends a row containing items. If necessary, the column count is increased to the size of items."
                        And no mention of rowCount.

                        My belief is that this should be interpreted as: of course the row count increases, as it would for anything, that goes without saying; if the columns in the row exceed current columns then you might not realize but the column count is increased [too].

                        The only other interpretation is that another is removed to maintain the row count, but then I think it would say and you would notice.

                        But it's pure speculation.

                        M 1 Reply Last reply 29 Jun 2018, 17:43
                        1
                        • J JonB
                          29 Jun 2018, 17:40

                          @mrjj

                          "Appends a row containing items. If necessary, the column count is increased to the size of items."
                          And no mention of rowCount.

                          My belief is that this should be interpreted as: of course the row count increases, as it would for anything, that goes without saying; if the columns in the row exceed current columns then you might not realize but the column count is increased [too].

                          The only other interpretation is that another is removed to maintain the row count, but then I think it would say and you would notice.

                          But it's pure speculation.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 29 Jun 2018, 17:43 last edited by
                          #18

                          @JonB
                          Also my belief so i wanted poster to test it out :)
                          by outputting rowCount before and after append.

                          J 1 Reply Last reply 29 Jun 2018, 17:44
                          1
                          • M mrjj
                            29 Jun 2018, 17:43

                            @JonB
                            Also my belief so i wanted poster to test it out :)
                            by outputting rowCount before and after append.

                            J Offline
                            J Offline
                            JonB
                            wrote on 29 Jun 2018, 17:44 last edited by
                            #19

                            @mrjj
                            I find it hard to believe it did not increase. Unless the row did not get added.

                            M 1 Reply Last reply 29 Jun 2018, 17:51
                            1
                            • J JonB
                              29 Jun 2018, 17:44

                              @mrjj
                              I find it hard to believe it did not increase. Unless the row did not get added.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 29 Jun 2018, 17:51 last edited by
                              #20

                              @JonB
                              me too. Worst name ever if it didnt.
                              So most likely poster had other issue.

                              1 Reply Last reply
                              0

                              16/20

                              29 Jun 2018, 16:10

                              • Login

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