code: def rowCount(self, parent):
          
  
          if parent.column() > 0:
              return 0
  
          if not parent.isValid():
              parentItem = self.root
          else:
              parentItem = parent.internalPointer()
  
          return parentItem.childCount()
docs: Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning the number of children of parent.