likage
2018-09-08 00:18:59 UTC
Hi all,
Given a list of strings, I am trying to populate the items in a tree view.
Here is my code:
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])
However, the hierarchy that I have got in my Tree View are not collapsible
(those with the small arrow icons by the side) and each row is appended
with values and editable (if double click), in which I do not want.
An example of the output from my code:
|Base
|Base|character
|Base|character|Mike
|Base|character|Mike|body
|Base
|Base|character
|Base|character|John
|Base
|Base|camera
where there are a few repeatable rows...
And this is what I am expecting:
|-- Base
|--|-- character
|--|--|-- Mike
|--|--|--|-- body
|--|-- character
|--|--|-- John
|--|-- camera
Any insights?
Given a list of strings, I am trying to populate the items in a tree view.
Here is my code:
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])
However, the hierarchy that I have got in my Tree View are not collapsible
(those with the small arrow icons by the side) and each row is appended
with values and editable (if double click), in which I do not want.
An example of the output from my code:
|Base
|Base|character
|Base|character|Mike
|Base|character|Mike|body
|Base
|Base|character
|Base|character|John
|Base
|Base|camera
where there are a few repeatable rows...
And this is what I am expecting:
|-- Base
|--|-- character
|--|--|-- Mike
|--|--|--|-- body
|--|-- character
|--|--|-- John
|--|-- camera
Any insights?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c59b034f-9786-4215-a807-4753642bb2d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c59b034f-9786-4215-a807-4753642bb2d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.