[SOLVED, moved] Drag from another application and drop to a PySide app?
-
Dear community,
I am trying to implement a dropEvent in a PySide application to open a file when someone drags it from the file explorer and drops it in the PySide application.
So I added self.setAcceptDrops(True) in the init of my MainWindow and implemented a dropEvent like that:
@
def init(self):
...
self.setAcceptDrops(True)
def dropEvent(self, *args, **kwargs):
print args@However, I cannot drop to my application.
The cursor is a ∅ that doesn't want me to drop there...How can I drop something in a PySide application?
Note: I tried adding setAcceptDrops(True) to inside widgets, it doesn't work neither.
-
You also have to implement the "dragEnterEvent()":http://doc.qt.nokia.com/4.7/qwidget.html#dragEnterEvent to tell the window system which drags you actually want to accept.
-
Oh yeah I didn't notice I have to "accept" the drag first, thanks ;)
If it helps anyone who was also wondering how to do a drag an drop in PySide, here is my working code:
@ @Slot(QDropEvent)
def dropEvent(self, event):
self.loadInputFile(self.dropFile)
@Slot(QDragEnterEvent)
def dragEnterEvent(self, event):
m = event.mimeData()
if m.hasUrls():
self.dropFile = m.urls()[0].toLocalFile()
event.acceptProposedAction()@