Delete row in QML TableView or all rows



  • Hello, is there anyway to delete rows in new QML TableView?



  • @Babs Hi,

    TableView doesn't own the data, that's the role of the model. So you need to delete content from the model.

    
    ListModel {
        id: libraryModel
        ListElement {
            title: "A Masterpiece"
            author: "Gabriel"
        }
        ListElement {
            title: "Brilliance"
            author: "Jens"
        }
        ListElement {
            title: "Outstanding"
            author: "Frederik"
        }
    }
    TableView {
        TableViewColumn {
            role: "title"
            title: "Title"
            width: 100
        }
        TableViewColumn {
            role: "author"
            title: "Author"
            width: 200
        }
        model: libraryModel
    }
    Button{
        onClicked: {
            if(libraryModel.count > 1)
                libraryModel.remove(0) //remove first row in the model
        }
    }
    


  • @Gojir4 Thank you.
    Regards,


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.