Results 1 to 2 of 2

Thread: How to remove a row from QML table?

  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default How to remove a row from QML table?

    Hi,
    I am working with QML Tableview.
    I want to remove selected row from TableView.
    How to remove a row from QML table?

    Model of tableview is QStandardItemModel.

    Qt Code:
    1. MyTableViewColumn {
    2. title: "delete"
    3. width: 15
    4. delegate:Image {
    5. id: name
    6. source: "images/delete.png"
    7. MouseArea{
    8. anchors.fill: parent
    9. anchors.margins: -10
    10. hoverEnabled:true
    11. cursorShape: Qt.PointingHandCursor
    12. onClicked: {
    13. tablemodel.selection.select(tablemodel.currentRow)
    14. myXML.removeRow(tablemodel.currentRow)
    15. tablemodel.currentRow++;
    16. }
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MyXML::removeRow(int index){
    2. // QModelIndex indexRaw=newMyModel->index(index, 0);
    3. newMyModel->removeRow(index);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by neda; 9th April 2016 at 06:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to remove a row from QML table?

    That looks ok.
    Although it is weird that you select the row that you are then deleting.

    Cheers,
    _

Similar Threads

  1. Multiple table delegates or a single table delegate?
    By karankumar1609 in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2014, 21:28
  2. Replies: 2
    Last Post: 25th June 2012, 10:54
  3. Replies: 2
    Last Post: 21st March 2012, 14:30
  4. Replies: 1
    Last Post: 8th June 2011, 14:13
  5. Replies: 0
    Last Post: 5th October 2010, 07:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.