Drag and drop files into a GUI using python and pyside




As an illustration, I've added a simple example of the python / pyside code for dragging an image file onto (a very simple) GUI. There are a number of examples on the web but I could find a simple demo of dragging and dropping files in a cross platform way.

This code includes a workaround for OSx because newer versions don't play that well with dragging and dropping in Qt4 and pyside doesn't support Qt5 (it's on the way)

Dependencies:
Obviously a python installation, pyside and Qt4 is required. On OSx I would recommend homebrew for installing python and Qt.

To workaround the issues with dragging and dropping on OSx with Qt4, NSURL is required. For this pyobjc is required. OSx specific install:
pip install -U pyobjc-core
pip install -U pyobjc
To run:
>>> python pyside_drag_drop_file.py

Output:
1) Run the GUI

2) Click the load image button or drag and drop an image onto the GUI



Code:





References: