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 3.9k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    1
    • SGaistS SGaist

      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 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 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
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #10

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

          J 1 Reply Last reply
          1
          • mrjjM mrjj

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

            J Offline
            J Offline
            JadeN001
            wrote on 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.

            mrjjM 1 Reply Last reply
            0
            • J JadeN001

              @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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              1
              • mrjjM mrjj

                @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 last edited by JadeN001
                #13

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

                mrjjM 1 Reply Last reply
                1
                • J JadeN001

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @JadeN001
                  ok, so u have to manage that yourself

                  JonBJ 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @JadeN001
                    ok, so u have to manage that yourself

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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....?

                    mrjjM 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @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....?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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.

                      JonBJ 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @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.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 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.

                        mrjjM 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @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.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #18

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

                          JonBJ 1 Reply Last reply
                          1
                          • mrjjM mrjj

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

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

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

                            mrjjM 1 Reply Last reply
                            1
                            • JonBJ JonB

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

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 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

                              • Login

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