Jump to content

Drag and drop QtWidget data to a parameter


Recommended Posts

As the title suggests, how do you drag and drop Qt data on to a parameter? I was able to use this example as reference. But in my case the i couldn't make the drop event register. The code i have now kinda works, but the dropped text is wierd.

What's the right way to do this....could use some help! I'm attaching an example code.

from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import hou

class TreeWidget(QTreeView):
    def __init__(self):
        super(TreeWidget, self).__init__()
#    def dragEnterEvent(self, event):
#        print "dragEnterEvent"
#        event.acceptProposedAction()
    def mouseMoveEvent(self, event):
        print "MoveEvent"
        mimeData = QMimeData()
        data = (self.selectedIndexes()[0]).data()
        drag = QDrag(self)
        drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)    
#    def dropEvent(self, event):
#        print "dropEvent"
#        mime_data = event.mimeData()


class Example(QWidget): 
    def __init__(self):
        super(Example, self).__init__()    
    def build_ui(self):
        self.setGeometry(300, 300, 150, 250)
        self.setParent(hou.qt.mainWindow(), Qt.Window)
        mainlayout = QVBoxLayout()
        self.tree_widget = TreeWidget()
        model = QStandardItemModel()
        for i in range(10):
            parent_item = QStandardItem('Example_{0} \nnew_line_{0} \n '.format(i))
    def dragEnterEvent(self, event):

#    def dropEvent(self, event):
#        print "dropEvent 2"
#        str = event.mimeData().text()
#        event.acceptProposedAction()

ex = Example()


Link to comment
Share on other sites

The docs in that example say: This example demonstrates specifically how to enable dragging items from other parts in Houdini and dropping them into the Python Panel interface.

So dragging anything to your custom widget makes sense, because you can handle different cases in your code, but dropping an arbitrary data from Qt into a Houdini's node parameter is undefined, to my knowledge. Native Houdini UI doesn't know how to handle this interaction. Interestingly that you're getting "something" working, I guess Houdini tries its best to read the mime data as text, but it's limited to what it can do.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...