PDA

View Full Version : tableview with proxy not refreshing on insertRow



BreakBad
5th March 2013, 17: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.

QSortFilterProxyModel:

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))

QAbstractItemModel:

def insertRow(self,index,obj):
self.beginInsertRows(index,0,1)
# 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
node._obj.append(obj)

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

self.endInsertRows()
self.rowsInserted.emit(index,0,1)
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.

alizadeh91
5th March 2013, 21: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 )

BreakBad
6th March 2013, 17: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....


self.beginInsertRows(index,0,0)