code: def get_root_item(self, item):
          
          root_item = item
          while isinstance(root_item.parent(), QTreeWidgetItem):
              root_item = root_item.parent()
          return root_item
docs: Return the root item of the specified item.