Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Delete row in QML TableView or all rows
Forum Updated to NodeBB v4.3 + New Features

Delete row in QML TableView or all rows

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml
3 Posts 2 Posters 1.1k Views 2 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.
  • B Offline
    B Offline
    Babs
    wrote on last edited by
    #1

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

    Gojir4G 1 Reply Last reply
    0
    • B Babs

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

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @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
          }
      }
      
      B 1 Reply Last reply
      3
      • Gojir4G Gojir4

        @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
            }
        }
        
        B Offline
        B Offline
        Babs
        wrote on last edited by
        #3

        @Gojir4 Thank you.
        Regards,

        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