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. Qtableview add rows based on other Qtableview
Forum Updated to NodeBB v4.3 + New Features

Qtableview add rows based on other Qtableview

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 408 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.
  • N Offline
    N Offline
    n-2204
    wrote on last edited by
    #1

    I have two table table1 and table2
    and in table1 i have option to add and del row so in table 2 i want rows as same as in table1 as if row added /del in table1 it should update in table2 as well
    how to do this ?
    thanks in advance

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

      connect(ui.tableView_1->model(), &QAbstractItemModel::rowsInserted, ui.tableView_2->model(),[&](const QModelIndex& parent, int first, int last){ui.tableView_2->model()->insertRows(first,1+last-first,parent);});
      and so on

      "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
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #2

        You just need to connect a slot to table1,&QAbstractItemModel::rowsRemoved/table1,&QAbstractItemModel::rowsInserted that deletes/inserts the coresponding row in table2

        "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
        1
        • N Offline
          N Offline
          n-2204
          wrote on last edited by VRonin
          #3

          @VRonin said in Qtableview add rows based on other Qtableview:

          QAbstractItemModel::rowsRemoved

          you mean using removeRow()and insertRow ?
          bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent = QModelIndex())
          bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent = QModelIndex())

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

            you mean using removeRow()and insertRow ?

            indeed

            "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
            • N Offline
              N Offline
              n-2204
              wrote on last edited by
              #5

              @VRonin said in Qtableview add rows based on other Qtableview:

              like this ??

              connect(ui.tableView_1->model(), &QAbstractItemModel::rowsInserted, ui.tableView_1->model(), [ui.tableView_1- >model()](const QModelIndex& parent, int first, int last)
              QAbstractItemModel* table1 = ui.tableView_1->model();
              QAbstractItemModel* table2 = ui.tableView_2->model();
              connect(table1, &QAbstractItemModel::rowsRemoved, table2, [table2](const QModelIndex& parent, int first, int last)
              
              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #6

                connect(ui.tableView_1->model(), &QAbstractItemModel::rowsInserted, ui.tableView_2->model(),[&](const QModelIndex& parent, int first, int last){ui.tableView_2->model()->insertRows(first,1+last-first,parent);});
                and so on

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

                • Login

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