Qt Forum

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

    Forum Updated on Feb 6th

    Unsolved TableView how to delete a row

    QML and Qt Quick
    2
    3
    891
    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.
    • morteasherah
      morteasherah last edited by morteasherah

      Hello to all. I have been using Qt/QtQuick for a project recently and I am stuck on deleting rows from a TableView. Below is the offending code

       TableView {
                      anchors.top: aBar.bottom
                      anchors.topMargin: 3
                      sortIndicatorVisible: true
                      frameVisible: false
                      Layout.fillWidth: true
                      Layout.fillHeight: true
                      onSortIndicatorColumnChanged: model.sort(sortIndicatorColumn, sortIndicatorOrder)
                      onSortIndicatorOrderChanged: model.sort(sortIndicatorColumn, sortIndicatorOrder)
                      id: dataView
      
                      TableViewColumn {
                          role: "Nome"
                          title: "Nome"
                          width: 200
                      }
      
                      TableViewColumn {
                          role: "Residenza"
                          title: "Residenza"
                          width: 200
                      }
      
                      TableViewColumn {
                          role: "Assicurazione"
                          title: "Assicurazione"
                          width: 200
                      }
      
                      TableViewColumn {
                          width: 128
                          resizable: false
      
                          delegate: RowLayout {
                                  anchors.fill: parent
                                  clip: true
      
                                  IconButton {
                                      iconName: "content/create"
                                      onClicked: console.log(styleData.row)
                                  }
      
                                  IconButton {
                                      iconName: "action/delete"
                                      onClicked: {
                                          console.log(styleData.row)
                                          sqlSortedData.eliminaCliente(styleData.row)
                                      }
                                  }
                          }
                      }
                      model: sqlSortedData
                  }
      
       Q_INVOKABLE void eliminaCliente(int row) {
              QSqlTableModel *sm = (QSqlTableModel*)sourceModel();
              sm->removeRow(row);
      }
      

      Ok, so where is the problem? The code correctly removes the columns that are part of the model, but this isn't the case for the last column, the one where I use the delegate to show the edit and delete buttons.

      I cannot figure out why it works this way.

      1 Reply Last reply Reply Quote 0
      • V
        vladstelmahovsky last edited by

        because they are not the part of the model?

        1 Reply Last reply Reply Quote 0
        • morteasherah
          morteasherah last edited by

          I thought the same. This implies that TableView redraws everything each time the model changes, right?

          I think I don't have a clear view of how TableView instantiates the row objects. If a row is not present in the model during the redraw operation, why the corresponding custom column is instantiated?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post