I'm pretty new to Python so please bear with me. I'm trying to populate a QTreeWidget from a tuple, but I can't seem to get it too work.
TreeList = ({
'Header1': ((
'Item1',
'Item2',
)),
'Header2': ((
'Item1',
'Item2'
))
})
The idea is that I want to create a QTreeWidget that looks like:
ROOT
|
|-- Header1
| |-- Item1
| |-- Item2
|
|-- Header2
|-- Item1
|-- Item2
I have been searching around online to find a solution, but nothing I try seems to work, what would be the best way to go about this.
widget = QTreeWidget()
for i in TreeList:
val = QTreeWidgetItem([i])
widget.addTopLevelItem(val)
for i in TreeList['Header1']
val = QTreeWidgetItem([i])
widget.Header1.addChild(val) # DONT THINK THIS IS RIGHT
for i in TreeList['Header2']
val = QTreeWidgetItem([i])
widget.Header2.addChild(val) # DONT THINK THIS IS RIGHT
The first for-loop works, and the headers get listed under the root element, but the second two for-loops don't work at all. What am I doing wrong? I have sifted through the documentation and everything suggests that I should used addChild() but PyCharm says:
'QTreeWidget' object has no attribute 'addChild'
I'm using Python 3.6 with PyQt5. Thanks!