Results 1 to 3 of 3

Thread: tableview with proxy not refreshing on insertRow

  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default tableview with proxy not refreshing on insertRow

    The removeRows method of my QSortFilterProxyModel and QAbstractItemModel seem to work. The QTreeView is redrawn and shows the removed rows are missing. However my insertRow method is not updating the QTreeView, however the data structure is correct after the insert is executed.

    QSortFilterProxyModel:
    Qt Code:
    1. def insertRow(self,parent,data):
    2. self.sourceModel().insertRow(self.mapToSource(parent),data)
    3.  
    4. def removeRows(self,row,count,parent):
    5. self.sourceModel().removeRows(self.mapToSource(parent).row(),1,self.mapToSource(parent))
    To copy to clipboard, switch view to plain text mode 

    QAbstractItemModel:
    Qt Code:
    1. def insertRow(self,index,obj):
    2. self.beginInsertRows(index,0,1)
    3. # get node from index
    4. node = self.getNode(index)
    5.  
    6. # wrap Node object around given Element
    7. new_node = Node(obj,node)
    8.  
    9. # append new element to parent element
    10. node._obj.append(obj)
    11.  
    12. # wrap any children with Node
    13. for child in obj.iterchildren():
    14. Node(child,new_node)
    15.  
    16. self.endInsertRows()
    17. self.rowsInserted.emit(index,0,1)
    18. return True
    To copy to clipboard, switch view to plain text mode 

    Upon futher investigation I found out that the rowsInserted signal is not being propagated back through the proxy to the view. I connected it manually but it does nothing. I've tried other methods such as emitting dataChanged. Using layoutAboutToBeChanged/layoutChanged and reset result in a seg fault.

    Note: The intent of insertRow is to insert a child node of the given index, only one row is required to be inserted. Is this the correct method? (Qt 4.7)

    Any help appreciated.

  2. #2
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: tableview with proxy not refreshing on insertRow

    First of all : rowsInserted is emitted but be aware that remove QPrivate... in fourth arg. when you call beginInsertRows(), no longer is needed to emit rowsInserted because in parent it will be emitted


    Added after 5 minutes:


    Be sure about arguments in this with your code : QAbstractItemModel::rowsInserted ( const QModelIndex & parent, int start, int end )
    Last edited by alizadeh91; 5th March 2013 at 21:56.

  3. #3
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: tableview with proxy not refreshing on insertRow

    I removed the unnecessary signals thanks. Also, I believe that since I am only inserting one child, the beginInsertRows(index,0,0) is what is needed. However the view is still not refreshed on insert. Remove still works.

    # remove given index, view successfully refreshed (row always == 1)
    Qt Code:
    1. self.beginRemoveRows(self.parent(index),row,row+count-1)
    To copy to clipboard, switch view to plain text mode 

    # insert one child of given index, view not refreshed....
    Qt Code:
    1. self.beginInsertRows(index,0,0)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. TableView/Proxy problem
    By poporacer in forum Newbie
    Replies: 6
    Last Post: 16th August 2011, 03:08
  2. QTableView insertRow 's dynamically
    By migel in forum Newbie
    Replies: 1
    Last Post: 30th June 2011, 13:08
  3. How to InsertRow Throught QSqlQueryModel ?
    By innobleday in forum Qt Programming
    Replies: 0
    Last Post: 24th March 2010, 04:44
  4. QStandardItemModel insertRow crashing
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2008, 11:55
  5. QTableView QTablemodel & insertRow
    By pfusterschmied in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 12:43

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.