Hi Ben,

There's a lot of ways to approach Drag and Drop, and none of them are particularly straightforward in my experience. The key to remember is that what is passed in a drag and drop operation is Mime Data (as you indicated you looked into) and not a direct object. My initial guess (and this is just that, so take it with a grain of salt) is that your event filter is responding to the source of the drop event (and qt_scrollarea_viewport is the internal viewport of the QTreeView where you installed the filter), not the source of the drag. Generally what I've had the most success with in drag and drop was encoding a set of data into a custom mime-type, and then in your drop handler you can read that mime data. Everything else has been unreliable. I'll whip up some sample code for you today and send it over.

In the meantime, the specific method(s) you're looking for (at least what I've had the most success with) is dropMimeData() in your TreeWidget (the destination), and mimeData() in your TableWidget (the source). mimeData(items) will encode data as you choose into a (potentially custom) mimeType, and then dropMimeData(parent, index, data, action) will decode that data and handle the results of the drop.

With that said, I've primarily worked in the QAbstractItemModel, QTreeView, and QTableView version so I could separate the model out, so this might be higher complexity than you're looking for. I'll let you know.

On 4/22/2015 6:46 AM, Benjam901 wrote:
Hello all,

I am having a bit of trouble with my QT Drag and Drop events. I am dragging an item from a QTableWidget (uiNodeUnit) and dropping it onto a QTreeWidget (uiUnitTree)

I have managed to set up an event filter on the QTreeWidget and when the item is dropped the event is fired. However I am struggling to return the name of the item that has been dragged in, I have looked into startDrag and mime data but no luck on my end so far. Is there some method that I am missing.

One extra thing, when I print source.objectName() the value is very odd indeed. The value I get returned is: qt_scrollarea_viewport should it be one of my widgets or have I set it up incorrectly?

Cheers,

Ben

My code is as follows:

12345678910111213       
# Inside the __init__ function
self.uiMainWindow.uiNodeUnit.setDragEnabled(True)
self.uiMainWindow.uiUnitTree.setDropIndicatorShown(True)
self.uiMainWindow.uiUnitTree.setAcceptDrops(True)
self.uiMainWindow.uiUnitTree.setDragEnabled(True)
self.uiMainWindow.uiUnitTree.viewport().installEventFilter(self)
def eventFilter(self, source, event):
#print source.objectName()
if (event.type() == QtCore.QEvent.Drop):
print "Event Filter"
return QtGui.QMainWindow.eventFilter(self, source, event)

--
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 [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d689de76-6699-41db-a808-8e3eca1fce5e%40googlegroups.com <https://groups.google.com/d/msgid/python_inside_maya/d689de76-6699-41db-a808-8e3eca1fce5e%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/5537C1EE.80509%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to