Drag and drop from Outliner into custom QTreeView

594 views
Skip to first unread message

Peter Makal

unread,
Jul 19, 2016, 2:49:40 PM7/19/16
to Python Programming for Autodesk Maya
Hey guys!

I'm writing a plugin in which I really like to have a drag and drop feature: copy selected objects from Maya Outliner into my own QTreeView. I started with obvious: setDragEnabled(True), setAcceptDrops(True) and setDropIndicatorShown(True) functions for my view. Didn't work. I overwrote  canDropMimeData and dropMimeData functions for my model with simple print instructions just to see if they will fire... Nope. So after some googling I came across MExternalDropCallback class in Maya API but it seems to work only the other way around - drag and drop from custom widget into Maya UI.

Is there any way to do this? In the end I can add a button saying something like: "Add selected objects" and just add them by using MSelectionList and not drag and drop behaviour but it seems less UI/UX friendly.

Marcus Ottosson

unread,
Jul 19, 2016, 3:13:13 PM7/19/16
to python_in...@googlegroups.com

I once had a go with this, but came up empty.

I ended up with something similar to what you suggest, but rather than making it a button I simply ran cmds.ls(selection=True) in the dropEvent and required users to first select the items they are about to drag. Not ideal, but was simple enough and works fine.


--
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/1b11ce11-e1cc-4e84-98a0-d2d240fd5965%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Jul 19, 2016, 6:25:06 PM7/19/16
to python_in...@googlegroups.com
I was trying to recall the discussions we had in the past about this, but I couldn't find anything. I don't remember what the result of my own experience with this was either. Does it really not register anything in the target widget, when you implement the dragEnterEvent() in the tree view? You are right that it would not be handled on the Maya Outliner side of things. A drag and drop operation kind of goes though this generic process where arbitrary mime data is delivered to the target. The target has to decide whether it can handle it.

But if I remember correctly, the data that is provided by dragging Maya's own tree view items is an internal and undocumented format. It was never useful to determine any information about it. So you would have to just identify that it is a Maya drag in general and then follow Marcus's suggestion of looking at the current selection.



Kurian O.S

unread,
Jul 19, 2016, 6:30:11 PM7/19/16
to python_in...@googlegroups.com

Justin Israel

unread,
Jul 19, 2016, 6:45:24 PM7/19/16
to python_in...@googlegroups.com
There it is!  :-)
And it looks like the response I got is still more specific to receiving the drop within a Maya UI element.  But the information is still valid that the mime data produce from the source Maya UI isn't really useful.
 
Reply all
Reply to author
Forward
0 new messages