def expand(node: QTreeWidgetItem, level: int): not_target = level != target_level node.setExpanded(not_target) if not_target: for i in range(node.childCount()): expand(node.child(i), level + 1)
def _expand_recursive(node: QTreeWidgetItem): """Expand node and its children.""" node.setExpanded(True) for i in range(node.childCount()): _expand_recursive(node.child(i))