On Tue, Sep 11, 2018 at 4:50 AM likage <dissidia....@gmail.com> wrote:
> Got it, many thanks for it, Justin! > > I have another question, the following is the working code: > class MyModel(QtGui.QStandardItemModel): > def __init__(self, parent=None): > super(MyModel, self).__init__(parent) > self.get_contents() > self.assets_column = 0 > > def get_contents(self): > self.clear() > contents = [ > '|Base|character|Mike|body', > '|Base|character|John', > '|Base|camera' > ] > > base_grp_icon = QtGui.QIcon('/user_data/base_grp_icon.png') # For > |Base > char_grp_icon = .QIcon('/user_data/char_grp_icon.png') # For > |Base|character > char_icon = .QIcon('/user_data/char_icon.png') # For > |Base|character|John > cam_icon = QtGui.QIcon('/user_data/cam_icon.png') # For > |Base|camera > > for content in contents: > parent = self.invisibleRootItem() > > > # content here will be `|Base|character|Mike|body` instead of > it iterating each and every item in that path > # node_type = cmds.nodeType(content) > # if node_type == "baseMain": > # icon = base_grp_icon > # if node_type == "charGrp": > # icon = char_grp_icon > # if node_type == "charMain": > # icon = char_icon > # if node_type == "camMain": > # icon = cam_icon > > > for word in content.split("|")[1:]: > child_items = [parent.child(i) for i in > range(parent.rowCount())] > for item in child_items: > if item.text() == word: > it = item > break > else: > it = QtGui.QStandardItem(word) > parent.setChild(parent.rowCount(), it) > parent = it > > > If I had wanted to append icons for each row, what is the best way that I > can do? > Those paths that you have seen in the code, are custom node types and if I > do `cmds.nodeType` as seen in that commented code portion, I will only be > able to iterate it based on the items found within the `contents` instead > of every item within... > If I understand correctly, you already know how to set the icon, but you are asking how to find these items in the hierarchy at a later point? Just to save a round trip in case you are asking about icons, you would want to use setIcon() on the first column item in each row. For the part about navigating your tree hierarchy, what you can do is save the maya path as data, and then search on this data later: http://doc.qt.io/archives/qt-4.8/qabstractitemmodel.html#match # Class variable MayaPath = QtCore.Qt.UserRole+1 # Save the maya path as a custom data role it = QtGui.QStandardItem(word) it.setData(content, self.MayaPath) # Find items later by the maya path idxs = self.match( self.index(0,0), self.MayaPath, content, flags=QtCore.Qt.MatchRecursive, )if not idxs: # not found it = self.itemFromIndex(idxs[0]) it.setIcon(...) -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/28092299-d377-41ad-ac96-2e1c7f5544bd%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/28092299-d377-41ad-ac96-2e1c7f5544bd%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2qN5YTE5_Cm%2B4%2Bzv17UnzwuAyQDNnpui-sgg95NZa1dA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.