【发布时间】:2019-02-13 07:17:48
【问题描述】:
给定一个字符串列表,我试图在树视图中填充项目。 这是我的代码:
class MyModel(QtGui.QStandardItemModel):
def __init__(self, parent=None):
super(MyModel, self).__init__(parent)
self.get_contents()
def get_contents(self):
self.clear()
contents = [
'|Base|character|Mike|body',
'|Base|character|John',
'|Base|camera'
]
for content in contents:
count = content.count('|')
for index in range(count):
index = index + 2
split_path = content.split('|')[0:index]
self.add_item(split_path)
def add_item(self,name):
item1 = QtGui.QStandardItem(name)
self.appendRow([item1])
但是,我在树视图中获得的层次结构不可折叠(旁边带有小箭头图标的那些),并且每一行都附加了值并且可编辑(如果双击),我不希望在其中.
我的代码的输出示例:
|Base
|Base|character
|Base|character|Mike
|Base|character|Mike|body
|Base
|Base|character
|Base|character|John
|Base
|Base|camera
其中有一些可重复的行...
这就是我所期待的:
|-- Base
|--|-- character
|--|--|-- Mike
|--|--|--|-- body
|--|-- character
|--|--|-- John
|--|-- camera
有什么见解吗?
【问题讨论】:
-
@eyllanesc 这将是 pyqt4
标签: python pyqt pyqt4 qtreeview