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 qgraphicsview 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. Maybe I'm still not understanding how to correctly implement widgets from QT Designer into code?

My code is fairly simple:

Qt Code:
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtCore import *
  3. from gui_from_designer import Ui_MainWindow
  4.  
  5. class mainWindow(QMainWindow, Ui_MainWindow):
  6.  
  7. def __init__(self, parent = None):
  8. super(mainWindow, self).__init__(parent)
  9. self.setupUi(self)
  10.  
  11. self.nodeWindow.setAcceptDrops(True)
  12.  
  13. #populate listwidget with icons
  14. path = os.path.dirname(sys.argv[0])
  15. for image in sorted(os.listdir(os.path.join(path, "images"))):
  16. if image.endswith(".png"):
  17. item = QListWidgetItem(image.split(".")[0].capitalize())
  18. item.setIcon(QIcon(os.path.join(path,
  19. "images/{}".format(image))))
  20. self.listWidget.addItem(item)
  21.  
  22. def dragEnterEvent(self, event):
  23. event.accept()
  24.  
  25. def dropEvent(self, event):
  26. event.accept()
  27.  
  28. def dragMoveEvent(self, event):
  29. event.accept()
  30.  
  31.  
  32. app = QApplication(sys.argv)
  33. form = mainWindow()
  34. form.show()
  35. app.exec_()
To copy to clipboard, switch view to plain text mode 

My qgraphicsview window is called nodeWindow. I figured maybe instead of:

Qt Code:
  1. def dragEnterEvent(self, event):
  2. event.accept()
To copy to clipboard, switch view to plain text mode 

I would change all the event.accept to self.nodeWindow.event.accept(), like:

Qt Code:
  1. def dragEnterEvent(self, event):
  2. self.nodeWindow.event.accept()
To copy to clipboard, switch view to plain text mode 

But no luck :-\

Is this a question where there is so much wrong with my code I should just start over? 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!