View Full Version : tableview with proxy not refreshing on insertRow

5th March 2013, 18:59
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.


def insertRow(self,parent,data):
self.sourceModel().insertRow(self.mapToSource(pare nt),data)

def removeRows(self,row,count,parent):
self.sourceModel().removeRows(self.mapToSource(par ent).row(),1,self.mapToSource(parent))


def insertRow(self,index,obj):
# get node from index
node = self.getNode(index)

# wrap Node object around given Element
new_node = Node(obj,node)

# append new element to parent element

# wrap any children with Node
for child in obj.iterchildren():

return True

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.

5th March 2013, 22:56
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 )

6th March 2013, 18:42
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)

self.beginRemoveRows(self.parent(index),row,row+co unt-1)

# insert one child of given index, view not refreshed....