younglegend Posted March 1, 2020 Share Posted March 1, 2020 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__() self.setDragEnabled(True) # def dragEnterEvent(self, event): # print "dragEnterEvent" # event.acceptProposedAction() def mouseMoveEvent(self, event): print "MoveEvent" mimeData = QMimeData() data = (self.selectedIndexes()[0]).data() mimeData.setText(data) drag = QDrag(self) drag.setMimeData(mimeData) 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__() self.build_ui() def build_ui(self): self.setGeometry(300, 300, 150, 250) self.setParent(hou.qt.mainWindow(), Qt.Window) mainlayout = QVBoxLayout() self.setLayout(mainlayout) self.tree_widget = TreeWidget() self.tree_widget.setRootIsDecorated(False) self.tree_widget.setHeaderHidden(True) model = QStandardItemModel() self.tree_widget.setModel(model) mainlayout.addWidget(self.tree_widget) for i in range(10): parent_item = QStandardItem('Example_{0} \nnew_line_{0} \n '.format(i)) model.appendRow(parent_item) def dragEnterEvent(self, event): event.acceptProposedAction() # def dropEvent(self, event): # print "dropEvent 2" # str = event.mimeData().text() # event.acceptProposedAction() ex = Example() ex.show() Quote Link to comment Share on other sites More sharing options...
younglegend Posted March 3, 2020 Author Share Posted March 3, 2020 bump Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 3, 2020 Share Posted March 3, 2020 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? Quote Link to comment Share on other sites More sharing options...
younglegend Posted March 3, 2020 Author Share Posted March 3, 2020 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. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 3, 2020 Share Posted March 3, 2020 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. Quote Link to comment Share on other sites More sharing options...
younglegend Posted March 3, 2020 Author Share Posted March 3, 2020 In that case, the only choice i have is to make my widget in python panel. Well that's a bummer. Thanks Alex! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.