1

Code below creates a single QTreeWidget. I want each "Root" item to display the "expand" arrow next to its name but I don't want to create the Root's children items yet (I would rather create the children items after the user clicks the "Expand" arrow. The the attached image illustrates the idea. How to achieve it?

app = QApplication([])

class Tree(QTreeWidget):
    def __init__(self, *args, **kwargs):
        super(Tree, self).__init__()
        self.setHeaderLabels(['Column name'])
        for i in range(3):
            root_item = QTreeWidgetItem()
            root_item.setText(0, 'Root %s' % i)
            self.addTopLevelItem(root_item)
        self.show()

tree = Tree()
app.exec_()

enter image description here

alphanumeric
  • 17,967
  • 64
  • 244
  • 392

0 Answers0