Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Drag'n'drop from Graph editor to QtWidget

matthias.richter
Contributor

Drag'n'drop from Graph editor to QtWidget

matthias.richter
Contributor
Contributor

Hi,

 

for an in-house extension I need to be able to drag nodes from the graph editor to a custom QtWidget written in Python in order the get their names, paths, etc.

 

I can drag them in the viewport to get into isolation mode but anywhere else.

 

The same custom widget works in Maya just fine when dropping nodes from the Outliner onto it.

 

Can this somehow be enabled?

 

Thanks,

 

Matthias

0 Likes
Reply
Accepted solutions (1)
698 Views
4 Replies
Replies (4)

marc.winter2
Advocate
Advocate

With an installed eventfiler on your ui, you can catch all the events

class MyEventFilter(QtCore.QObject):
    def __init__(self, _parent):
        super(MyEventFilter, self).__init__()
        self.parent = _parent
    
    def eventFilter(self, _obj, _event):
        if _event.type() == QtCore.QEvent.Close:
            if not self.on_close():
                _event.ignore()
                return True
        elif _event.type() == QtCore.QEvent.Type.DragEnter:
            if _event.mimeData().hasFormat('application/vred-tree-item'):
                _event.accept()
            
            for tempFormatStr in _event.mimeData().formats():
                print '"' + tempFormatStr + '"'
                print '"' + str(_event.mimeData().hasFormat(tempFormatStr)) + '"'
                print '"' + str(_event.mimeData().data(tempFormatStr)) + '"'
        
        elif _event.type() == QtCore.QEvent.Type.DragLeave:
            pass
        elif _event.type() == QtCore.QEvent.Type.DragMove:
            pass
        elif _event.type() == QtCore.QEvent.Type.Drop:
            tempNodes = getSelectedNodes()
            _event.setDropAction(QtCore.Qt.CopyAction)
            _event.accept()
        
        return super(type(self), self).eventFilter(_obj, _event)

 

self.eventFilter = MyEventFilter(self)
self.ui.installEventFilter(self.eventFilter)

The correct format for the data seems to be "application/vred-tree-item"

But i do not know how to get the nodes. Anyone has an idea?

As a workaround you can maybe use the selectedNodes.

 

Best regards Marc

 

matthias.richter
Contributor
Contributor

Marc, thank you!

 

It works as far as I'm too getting the QMimeData of type "application/vred-tree-item". Each entry is exactly 8 bytes long. After having dragged and dropped a couple of nodes from the graph it's obvious that child nodes are not being considered but only their parents. Works for me.

 

Big question to the VRED dev team is: How to decode that data? What's inside it?

 

Thank you,

 

Matthias

0 Likes

matthias.richter
Contributor
Contributor

Ok, I dug a little bit deeper into this since the getSelectedNodes() workaround has the drawback that I would have to filter child nodes whose parents are already in the selection. Not a fan of overcomplicating it.

 

Since dropping a node into the viewport results in entering isolation mode with that particular geometry it is actually possible to extract the data from the tree view. Converting the mime data to hex results in a memory address. I do not know where to go from here. Any cast I tried to some class or inherited class coming from the QStandardItem did fail.

 

Help is highly appreciated here 🏳️

 

Matthias

0 Likes

matthias.richter
Contributor
Contributor
Accepted solution

Update: I found that neat function vrScenegraph.getSelectedRootNodes() which does exactly I was looking for in terms of filtering all unnecessary child nodes.

 

If only the API docs weren't that sparse 🤔

 

-Matthias