def get_all_top_level_items(tree_widget):
    """
    Returns all the top level items of the QTreeWidget

    :param tree_widget: your QTreeWidget
    :return: list of QTreeWidgetItems
    """

    items = []
    for index in range(tree_widget.topLevelItemCount()):
        items.append(tree_widget.topLevelItem(index))
    return items