Jump to content
Sign in to follow this  

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()


Share this post

Link to post
Share on other sites

Need more information,

What kind of "parameter" are you talking about? A Houdini parameter, a QWidget?

What is so "weird" in that text?

What and whereto are you dragging exactly?

Share this post

Link to post
Share on other sites

I'm dragging the text from the QWidget (QTreeView) to a wrangle node. Right now when i drop the text on to a wrangle, it copies only the first line and the rest shows up when i delete those lines.

Share this post

Link to post
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.


Share this post

Link to post
Share on other sites

In that case, the only choice i have is to make my widget in python panel. Well that's a bummer. Thanks Alex! 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this