Python 禁用在QTreeWidget中选择父行
我在QTreeWidget中填充嵌套列表,需要禁用父行的选择 代码是:Python 禁用在QTreeWidget中选择父行,python,selection,pyside,qtreewidget,Python,Selection,Pyside,Qtreewidget,我在QTreeWidget中填充嵌套列表,需要禁用父行的选择 代码是: def fillTree(self): ''' Fill UI with list of parts ''' roots = ['APLE', 'ORANGE', 'MANGO'] childs = ['body', 'seed', 'stern'] parent = self.treeWidget.invisibleRootItem() for root in roo
def fillTree(self):
'''
Fill UI with list of parts
'''
roots = ['APLE', 'ORANGE', 'MANGO']
childs = ['body', 'seed', 'stern']
parent = self.treeWidget.invisibleRootItem()
for root in roots:
widgetTrim = QTreeWidgetItem()
widgetTrim.setText(0, root)
parent.addChild(widgetTrim)
for child in childs:
widgetPart = QTreeWidgetItem()
widgetPart.setText(0, child)
widgetTrim.addChild(widgetPart)
我需要避免选择“水果”项目。您必须从以下列表中删除
Qt.itemisselect
:
这些标志是一个OR组合
ItemFlag
值。因此,使用AND NOT操作从现有标志组合中删除ItemIsSelectable
。QTreeView或QTreeWidget?QTreeWidgetItemMain小部件-QTreeWidget@kiryha. 它是按位的,而不是按位的。这些标志是或组合在一起的,因此它接受所有当前标志,但没有可选标志。
widgetTrim = QTreeWidgetItem()
widgetTrim.setFlags(widgetTrim.flags() & ~Qt.ItemIsSelectable)