I have this simple script which uses PySide2 although I tried the same script with PyQt5 with the same result. I am trying to drag & drop files onto my window and get their file path:
import sys
from PySide2.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().hasUrls():
e.acceptProposedAction()
def dropEvent(self, e):
for url in e.mimeData().urls():
file_name = url.toLocalFile()
print("Dropped file: " + file_name)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
On my system this does not allow drag & drop actions to this window. dragEnterEvent
is never called. Am I missing something?