views:

108

answers:

1

I know there is the possibility of setting the parent model index for the item view, but I'd like to do this for the model.

The reason is quite simple, I want to get rid of those constructs:

# PyQt 4.5.4, but this should be similar to Qt.
def insertRows(self, row, count, parent=QModelIndex()):
    if parent.isValid():
        parentNode = parent.internalPointer()
    else:
        parentNode = self.rootNode
A: 

If your model represents flat structure, just ignore parent attribute or use QModelIndex() everywhere you have to specify parent. If your model represents the tree, you can't really get rid of the constructs you posted, because someone may use invalid index and you have to check if it's valid.

chalup