Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Qtableview add rows based on other Qtableview

    General and Desktop
    2
    6
    91
    Loading More Posts
    • 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
      n-2204 last edited by

      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 Reply Quote 0
      • VRonin
        VRonin last edited by

        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 Reply Quote 1
        • VRonin
          VRonin last edited by VRonin

          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 Reply Quote 1
          • N
            n-2204 last edited by VRonin

            @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 Reply Quote 0
            • VRonin
              VRonin last edited by

              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 Reply Quote 0
              • N
                n-2204 last edited by

                @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 Reply Quote 0
                • VRonin
                  VRonin last edited by

                  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 Reply Quote 1
                  • First post
                    Last post