[Moved] Drag/Drop from ListWidget to GraphicsView
-
Hello! I'm having troubles getting the drag/drop functionality to work between a listwidget and a qgraphicsview. I can not, for the life of me, figure out how to get the qgrahicsview to show the icon when I drop it into the window. I first actually designed the layout with QT Designer. So gui_from_designer is just the python file that was translated from the ".ui" file. My code is fairly simple:
@from PyQt4.QtGui import *
from PyQt4.QtCore import *
from gui_from_designer import Ui_MainWindow@@class mainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent = None): super(mainWindow, self).__init__(parent) self.setupUi(self) self.nodeWindow.setAcceptDrops(True) #populate listwidget with icons path = os.path.dirname(sys.argv[0]) for image in sorted(os.listdir(os.path.join(path, "images"))): if image.endswith(".png"): item = QListWidgetItem(image.split(".")[0].capitalize()) item.setIcon(QIcon(os.path.join(path, "images/{}".format(image)))) self.listWidget.addItem(item) def dragEnterEvent(self, event): event.accept() def dropEvent(self, event): event.accept() def dragMoveEvent(self, event): event.accept()
app = QApplication(sys.argv)
form = mainWindow()
form.show()
app.exec_()@My qgraphicsview window is called nodeWindow. I figured maybe instead of:
@def dragEnterEvent(self, event):
event.accept()@I would change all the event.accept to self.nodeWindow.event.accept():
@def dragEnterEvent(self, event):
self.nodeWindow.event.accept()@But with no luck. I'm still fairly new to PyQt and the way drag/drop works with QGraphicsView so any input would be greatly, greatly appreciated! Thanks so much!
edit: Fixed formatting for the code!