Results 1 to 10 of 10

Thread: Removing row from QAbstractItemModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Removing row from QAbstractItemModel

    Hi all,

    I'm using QML treeview with model sub-classed from QAbstractItemModel.
    I'm facing this issue that model indexes aren't updated when user removes a row.

    Here's the code
    Qt Code:
    1. bool TreeModel::removeRows(int row, int count, const QModelIndex &parent)
    2. {
    3. TreeItem *parentItem = getItem(parent);
    4.  
    5. if(parentItem == null) return false;
    6.  
    7. bool success = false;
    8.  
    9. if (count > 0)
    10. {
    11. beginRemoveRows(parent, row, row + count - 1);
    12. success = parentItem->removeChildren(row, count);
    13. endRemoveRows();
    14. }
    15.  
    16. return success;
    17. }
    18.  
    19. bool TreeItem::removeChildren(int position, int count)
    20. {
    21. if (position < 0 || position + count > children_.size())
    22. return false;
    23.  
    24. for (int row = 0; row < count; ++row)
    25. delete children_.takeAt(position);
    26.  
    27. return true;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Could you point what am I missing?
    Last edited by volcano; 28th June 2016 at 12:19.

Similar Threads

  1. QAbstractItemModel on QGraphicsView
    By wagmare in forum Newbie
    Replies: 0
    Last Post: 24th May 2012, 08:06
  2. qAbstractItemView, QAbstractItemModel...
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 18th May 2009, 09:22
  3. QAbstractItemModel with rowSpan?
    By joeld42 in forum Qt Programming
    Replies: 0
    Last Post: 4th February 2009, 18:53
  4. QAbstractItemModel question
    By awhite1159 in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2008, 09:11
  5. Help needed with QAbstractItemModel
    By Harvey West in forum Qt Programming
    Replies: 11
    Last Post: 27th November 2006, 12:06

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.