Issues with treeview and selections

43 views
Skip to first unread message

kiteh

unread,
Sep 12, 2018, 6:23:40 PM9/12/18
to Python Programming for Autodesk Maya
Hi all, I am having some issues with QTreeView where I populates the information from another model.

While trying to perform the selection within the tree view, it is suppose to be returning me the full path of the selection. However for some reasons, there is always a 'NoneType' object/ something in which it will returns me 2 items - the selection and a None.

For example, if I have the following tree:
* ObjectA
** ObjectB
*** ObjectC

# And selected ObjectC, the full path should be - |ObjectA|ObjecBA|ObjectC but instead I got |None|ObjectA|ObjecBA|ObjectC


One way that I have rectified this problem is using `try... except <either Attribute or TypeError>` in the selectionChanged connection for the tree view and for the displaying of data in the model where it checks if the role equates to `QtCore.Qt.DisplayRole`.

About the latter - Correct me if I am wrong, but doesn't QtCore.Qt.DisplayRole valid only if there are characters/strings in the field? If so, it should not be deriving the empty values, right?

This is the script - https://pastebin.com/xTavZfhP
(I apologize in advance that the code may not work on a typical maya scene for some portions within are custom stuff used. Also I have listed out the error portions, search using #>>>)


Appreciate for any insights!

Justin Israel

unread,
Sep 12, 2018, 7:03:32 PM9/12/18
to python_in...@googlegroups.com


On Thu, Sep 13, 2018, 10:23 AM kiteh <kiteh...@gmail.com> wrote:
Hi all, I am having some issues with QTreeView where I populates the information from another model.

While trying to perform the selection within the tree view, it is suppose to be returning me the full path of the selection. However for some reasons, there is always a 'NoneType' object/ something in which it will returns me 2 items - the selection and a None.

For example, if I have the following tree:
* ObjectA
** ObjectB
*** ObjectC

# And selected ObjectC, the full path should be - |ObjectA|ObjecBA|ObjectC but instead I got |None|ObjectA|ObjecBA|ObjectC


One way that I have rectified this problem is using `try... except <either Attribute or TypeError>` in the selectionChanged connection for the tree view and for the displaying of data in the model where it checks if the role equates to `QtCore.Qt.DisplayRole`.

About the latter - Correct me if I am wrong, but doesn't QtCore.Qt.DisplayRole valid only if there are characters/strings in the field? If so, it should not be deriving the empty values, right?

That isn't correct. It's just data like anything else. But it is used as the display value. If your node returns None for its DisplayRole then it could get converted to a string. 


This is the script - https://pastebin.com/xTavZfhP
(I apologize in advance that the code may not work on a typical maya scene for some portions within are custom stuff used. Also I have listed out the error portions, search using #>>>)

Looks like your issue is related to this spot:

@property
def name(self):
    return self._node.key()

I don't know what type your node is but if key() is returning None, then that is what you are getting in your model for the display role. 
Make sure you are also accounting for your root node. It should be an empty string for the name? Maybe what you need to do is:

@property
def name(self):
    return self._node.key() or '' 





Appreciate for 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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4248b8a9-d0b2-4941-9820-cec6db96a5e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kiteh

unread,
Sep 13, 2018, 7:12:37 PM9/13/18
to Python Programming for Autodesk Maya
Thanks, I will take a look!
Reply all
Reply to author
Forward
0 new messages