您可以使用QTreeWidgetItem的setChildIndicatorPolicy()函数来控制父项节点箭头的显示。这个函数有三个选项: QTreeWidgetItem::ShowIndicator、QTreeWidgetItem::DontShowIndicator和QTreeWidgetItem::DontShowIndicatorWhenChildless。
如果您想要在设置了缩进后显示父项节点的箭头,可以将其值设置为QTreeWidgetItem::ShowIndicator。例如:
treeWidget->setIndentation(20);
treeWidget->setRootIsDecorated(false); // 隐藏根节点的箭头
QTreeWidgetItem* parent = new QTreeWidgetItem(treeWidget);
parent->setText(0, "Parent node");
parent->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
QTreeWidgetItem* child = new QTreeWidgetItem(parent);
child->setText(0, "Child node");
这样就可以在父项节点旁边显示一个箭头,用于展开或折叠子项节点。