I am going through various PySide tutorials, now learning tree views, and trying to understand a couple of things. In the Model class, there is a parent method which (if I am not mistaken) takes in the model, and an index, and returns the index of its parent node. The parent() method calls the built-in method createIndex(), which at the documentation usage is described thusly:
def createIndex(row, column, ptr): Creates a model index for the given row and column with the internal pointer ptr
While that is from Qt, the description is the same at PySide documentation site too.
And in the treemodel tutorial example, within the parent() method, it is used as follows (trimming away some inessential details):
def parent(self, childIndex):
childNode = childIndex.internalPointer() #internal pointer returns node corresponding to index
parentNode = childNode.parent() #this instance of parent() is defined in the TreeItem class
return self.createIndex(parentNode.row(), 0, parentNode) #second input is 0 by convention for tree parent
def parent(self, childIndex):
childNode = childIndex.internalPointer() #internal pointer returns node corresponding to index
parentNode = childNode.parent() #this instance of parent() is defined in the TreeItem class
return self.createIndex(parentNode.row(), 0, parentNode) #second input is 0 by convention for tree parent
To copy to clipboard, switch view to plain text mode
My question is this: while we indeed use the internal pointer to pull the childNode, this is not the third input to createIndex. Rather, the input to createIndex is simply the parent node which we have pulled from the childNode. So it seems I am not feeding it an internalPointer at all, but simply something I have extracted from the internalPointer.
Why describe the third parameter as a pointer when it seems to just be an object (i.e., an item/node in your tree)? Given that I am working in Python, which does not use pointers, what is the third input (and for that matter what is an internalPointer anyway, in Python?).
Note crossposted at SO:
http://stackoverflow.com/questions/2...-use-a-pointer
Bookmarks