Last active
March 16, 2022 18:41
-
-
Save oglops/dbbb0e8db70dc0fb7b2ae6809deafb71 to your computer and use it in GitHub Desktop.
Attempt to cheat maya into thinking that my custom drag is from script editor, but it did not work, even if I used pickled "real" data when dragging from script editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def startDrag(self, supportedActions): | |
print('start drag') | |
listsQModelIndex = self.selectedIndexes() | |
if listsQModelIndex: | |
# dataQMimeData = self.model().mimeData(listsQModelIndex) | |
# insert fake x-maya-data | |
dataQMimeData = QtCore.QMimeData() | |
encoded = QtCore.QByteArray() | |
# failed attempt to cheat maya | |
# import pickle | |
# encoded = pickle.load( open( "/tmp/fake", "rb" ) ) | |
# dataQMimeData.setData('application/x-maya-data', encoded) | |
dataQMimeData.setData('text/plain', 'random text') | |
print('current formats', dataQMimeData.formats()) | |
if not dataQMimeData: | |
return None | |
dragQDrag = QtGui.QDrag(self) | |
# disable widget screenshot | |
# dragQDrag.setPixmap(QtGui.QPixmap('test.jpg')) # <- For put your custom image here | |
dragQDrag.setMimeData(dataQMimeData) | |
defaultDropAction = QtCore.Qt.IgnoreAction | |
if ((supportedActions & QtCore.Qt.CopyAction) and (self.dragDropMode() != QtWidgets.QAbstractItemView.InternalMove)): | |
defaultDropAction = QtCore.Qt.CopyAction; | |
dragQDrag.exec_(supportedActions, defaultDropAction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment