pyqt / python-qt5

Unofficial PyQt5 via PyPI for Python 2.7 64-bit on Windows
GNU General Public License v3.0
280 stars 77 forks source link

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

Closed Li-Green closed 1 year ago

Li-Green commented 1 year ago

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_()