InvisibleRootItem

947 views
Skip to first unread message

Bay

unread,
Oct 16, 2013, 5:05:27 AM10/16/13
to python_in...@googlegroups.com
Hi all, 
         I was looking through PyQT docs on QTreeWidget and was wondering the use of the InvisibleRootItem command. Is it supposed/could it be used to provide a main parent for a QTreeView gui? Or am I mistaken about its usage?

Thank you 
Gann Boon Bay

Justin Israel

unread,
Oct 16, 2013, 6:38:42 AM10/16/13
to python_in...@googlegroups.com
Ya that is the usage. Its the root item under which your own items are first parented.  


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0cd3dae3-64c4-4486-a7d7-67e2b53a72be%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bay

unread,
Oct 16, 2013, 1:23:48 PM10/16/13
to python_in...@googlegroups.com
Hi Justin, 
              thanks for your input again. I'm just trying to see if I could adapt Yasin Uludug's tutorials into something I could use in Maya. A problem I found in the tutorial is that there's a need to specify a rootnode to parent all the items under and I'm trying to find a way around that (Since if I want to select something and add to the list, I want the selection displayed, rather than hidden as a parent). Would this be how I would use it? 

        self.treeWidget = QtGui.QTreeWidget()
        self.rootNode = self.treeWidget.invisibleRootItem()
        self._model=testtree.SceneGraphModel(self.rootNode)
   
        I'm running into some errors right now but I want to try and see if i could resolve it first. 


Justin Israel

unread,
Oct 16, 2013, 3:01:00 PM10/16/13
to python_in...@googlegroups.com

The invisible root item of a QTreeWidget is a QTreeWidgetItem and is the equivalent to Maya's World. If an object in Maya has no parent, technically it is a child of the World.
When you place one or more QTreeWidgetItems under the root item, they will become visible in your tree as the first top level items. Then you can continue nesting children under those child items.
Aside from that, I am not clear what the conflict is. Maybe you could provide more context from the usage and the tutorial you are following?

--
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_m...@googlegroups.com.

Bay

unread,
Oct 16, 2013, 3:17:33 PM10/16/13
to python_in...@googlegroups.com
Hi Justin, 
              thank you so much for your explanation.


              The conflict right now that I'm getting is while I could use a QTreeWidget's invisible root item and set it up as my "World", I seemed to be unable to add child items to my model and lost access to my Node class that processed the information from my Model. 

Getting errors such as this:
# TypeError: QTreeWidgetItem.insertChild(int, QTreeWidgetItem): argument 2 has unexpected type 'Node'


What I'm trying to make is a more interactive selection set menu where I can add/remove/rename objects from the menu. Attached are my files if that would help. 

Again thank you for the assistance. 
selectorGUI.py
testtree.py

Justin Israel

unread,
Oct 16, 2013, 4:22:52 PM10/16/13
to python_in...@googlegroups.com
Unfortunately I can't watch the video at the moment to see what is being suggested (will check that out later) but I can already tell you that you are mixing pieces together that don't normally go together.

QTreeWidget is a convenience class meant to act as a standalone widget. it contains its own internal model and represents the data as QTreeWidgetItems. You interact at the item level to add children.

QAbstractItemModel is the abstract base class for creating model/view implementations. In this approach, you can store whatever private data structure you want, and implement the interface to make the model suitable to be used with views like QTreeView.

QTreeWidgetItem (including the root item) accept only QTreeWidgetItem subclasses, which is where you error comes from. My assumption is that the appropriate approach would be to store your custom Node structure within the model, and then simply plug the model into a QTreeView to visualize it. If you are working with a QTreeWidget, then you should have no use for a custom model.



--
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_m...@googlegroups.com.

Bay

unread,
Oct 16, 2013, 4:55:00 PM10/16/13
to python_in...@googlegroups.com
Hi Justin,
               thanks for replying. Yea I realized that after spending the morning trying to find an answer to it. Right now I can only set the World as an string "Root' to store the data. But it feels somewhat....inelegant. So I'm just hunting for a better way of doing it. 
Reply all
Reply to author
Forward
0 new messages