Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
5.9.0 Alpha
-
None
Description
Directed to post a bug after posting a question here:
https://forum.qt.io/topic/76961/expand-all-qtreewidget-items-and-hide-all-expansion-indicators/3
I don't want the user to be able to collapse the nodes, so I use setChildIndicatorPolicy:
QTreeWidgetItem* last = tree->topLevelItem(tree->topLevelItemCount() - 1); while(last) { last->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); last = last->child(last->childCount() - 1); }
However, doing this hides all the children below the first level
The documentation for QTreeWidgetItem::DontShowIndicator says
The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.
Manually setting the item expanded doesn't work
QTreeWidgetItem* last = tree->topLevelItem(tree->topLevelItemCount() - 1); while(last) { last->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); last->setExpanded(true); last = last->child(last->childCount() - 1); }
Note that QTreeModel::hasChildren always returns {[false}} if the indicator policy is don't show.