Reputation: 3993
I'm trying to add some check boxes to the children in a QTreeViewWidget, but they are not showing.
TreeList = ({
'Header1': (('Item1', 'Item2', )),
'Header2': (('Item1', 'Item2', )),
})
tree = QTreeWidget()
for key, value in TreeList.items():
parent = QTreeWidgetItem(tree, [key])
for val in value:
child = QTreeWidgetItem([val])
child.setFlags(child.flags() | Qt.ItemIsUserCheckable)
parent.addChild(child)
The TreeViewList populates as it should, but the checkboxes are not there, any ideas?
Upvotes: 1
Views: 2145
Reputation: 243907
You have to set a value to the checkbox:
child.setCheckState(0, Qt.Unchecked)
In your case:
app = QApplication(sys.argv)
TreeList = ({
'Header1': (('Item1', 'Item2', )),
'Header2': (('Item1', 'Item2', )),
})
tree = QTreeWidget()
for key, value in TreeList.items():
parent = QTreeWidgetItem(tree, [key])
for val in value:
child = QTreeWidgetItem([val])
child.setFlags(child.flags() | Qt.ItemIsUserCheckable)
child.setCheckState(0, Qt.Unchecked)
parent.addChild(child)
tree.show()
sys.exit(app.exec_())
Upvotes: 2