pyqt/python-qt5

pyqtgraph: there is no action when drop something to pyqtgraph.PlotWidget

Li-Green opened this issue · 0 comments

Hi, Sorry to bother you, I want to drag item of tree to pyqtgraph.PlotWidget. But looks like dropEvent() doesn't work for pyqtgraph. I tried drag '.txt', '.png', I can only get "dragEnterEvent triggered" and "Get file", I can't get "dropEvent triggered".
Could you please give some advice?

The code is as below:

from PyQt5 import QtWidgets
import pyqtgraph as pg

class MyPlotWidget(pg.PlotWidget):
def init(self, parent=None):
super().init(parent)
self.setAcceptDrops(True)

def dragEnterEvent(self, event):
    print("dragEnterEvent triggered")
    if event.mimeData().hasUrls():
        event.acceptProposedAction()
        print("Get file")
    else:
        event.ignore()
        print("Ignore file")

def dropEvent(self, event):
    print("dropEvent triggered")
    for url in event.mimeData().urls():
        file_path = url.toLocalFile()
        print("Dropped file:", file_path)

if name == 'main':
app = QtWidgets.QApplication([])
win = QtWidgets.QMainWindow()
plot = MyPlotWidget()
win.setCentralWidget(plot)
win.show()
app.exec_()