code: def parent(self, index):
          
          if not index.isValid():
              return QtCore.QModelIndex()
  
          childItem = self.getItem(index, altItem=self.invisibleRootItem)
          parentItem = childItem.parentItem
  
          if parentItem == self.invisibleRootItem:
              return QtCore.QModelIndex()
  
          return self.createIndex(parentItem.childNumber(), 0, parentItem)
docs: Returns the parent of the model item with the given index. If the item has no parent,
              an invalid QModelIndex is returned.
  
              A common convention used in models that expose tree data structures is that only items
              in the first column have children. For that case, when reimplementing this function in
              a subclass the column of the returned QModelIndex would be 0. (This is done here.)
  
              When reimplementing this function in a subclass, be careful to avoid calling QModelIndex
              member functions, such as QModelIndex.parent(), since indexes belonging to your model
              will simply call your implementation, leading to infinite recursion.