code: def parent(self, index):
          
          if not index.isValid():
              return QtCore.QModelIndex()
  
          childItem = index.internalPointer()
          # the only place where the parent item is queried
          parentItem = childItem.getParent()
  
          if parentItem == self.root:
              return QtCore.QModelIndex()
  
          return self.createIndex(parentItem.row(), 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.