[PyQt] Problem on insert rows when using QTreeView with QSortFilterProxyModel
Gabriel Reis
gabrielcnr at gmail.com
Fri Jan 13 13:33:01 GMT 2012
Oops!
Sorry, I forgot completely about that piece of code.
The TreeModel class code is found below:
class TreeModel(QAbstractItemModel):
def columnCount(self, parent):
if parent.isValid():
return parent.internalPointer().columnCount()
else:
return self.rootItem.columnCount()
def get_item(self, index):
if not index.isValid():
return None
item = index.internalPointer()
return item
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return None
if role != Qt.DisplayRole:
return None
item = index.internalPointer()
data = item.data(index.column())
return data
def flags(self, index):
if not index.isValid():
return Qt.NoItemFlags
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.rootItem.data(section)
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QModelIndex()
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
childItem = parentItem.child(row)
if childItem:
return self.createIndex(row, column, childItem)
else:
return QModelIndex()
def parent(self, index):
if not index.isValid():
return QModelIndex()
childItem = index.internalPointer()
parentItem = childItem.parent()
if parentItem == self.rootItem:
return QModelIndex()
return self.createIndex(parentItem.row(), 0, parentItem)
def rowCount(self, parent):
if parent.column() > 0:
return 0
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
return parentItem.childCount()
Many thanks,
Gabriel
On Fri, Jan 13, 2012 at 12:13 PM, Benjamin Kloster <
benjamin.kloster at videlco.eu> wrote:
> Without the lsfw2 module, it's hard to test on my end, but have you tried
> keeping around a reference to the sourceModel? The Qt documentation doesn't
> mention whether the proxy model assumes ownership. If it doesn't, the
> source model will be garbage collected.
> ______________________________**_________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.**com/mailman/listinfo/pyqt<http://www.riverbankcomputing.com/mailman/listinfo/pyqt>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120113/81cf8a59/attachment.html>
More information about the PyQt
mailing list