Solved Can QTreeWidget have checkboxes at top level if there are no sub-nodes for that parent element?
-
I create an item at the top level with the following code.
l1 = QTreeWidgetItem(["String A", "String B", "String C","String D"]) l1.setFlags(l1.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable) l1.setTextAlignment(2, QtCore.Qt.AlignRight)
Everything works fine and the checkbox shows up but only if there are sub-nodes, i.e. child elements. For some top level nodes there are no child elements but I need a checkbox with them. Is that possible? Thanks.
-
@ACollins Is it same if you remove Qt.ItemIsTristate ?
-
@Denni-0 The key was the third line: treItem_1.setCheckState(3, Qt.Unchecked)
I put that in and it started working. I thought it would default to the unchecked state but guess not. Thanks for the tip.