I am trying to drag an icon from the desktop onto my application, which is nothing more than an empty QGraphicsView window. I receive a QDragEnterEvent, but when I release the mouse button, I do not receive a QDropEvent. What am I doing wrong? Here's my simplified code. Thanks for your help!

Qt Code:
  1. #include <QtGui/QApplication>
  2. #include <QMainWindow>
  3. #include <QGraphicsView>
  4. #include <QDragEnterEvent>
  5. #include <QDropEvent>
  6. #include <QGraphicsSceneDragDropEvent>
  7.  
  8. class MyGraphicsView : public QGraphicsView
  9. {
  10. //Q_OBJECT // Do I need Q_OBJECT?
  11.  
  12. public:
  13. MyGraphicsView(QGraphicsScene *parent=0);
  14.  
  15. protected:
  16. void dragEnterEvent(QDragEnterEvent *event);
  17. void dropEvent(QDropEvent *event);
  18. //void dropEvent(QGraphicsSceneDragDropEvent *event);
  19. };
  20.  
  21. MyGraphicsView::MyGraphicsView(QGraphicsScene *parent)
  22. : QGraphicsView(parent)
  23. {
  24. setAcceptDrops(true);
  25. }
  26.  
  27. void MyGraphicsView::dragEnterEvent(QDragEnterEvent *event)
  28. {
  29. //event->setDropAction(Qt::IgnoreAction);
  30. event->accept();
  31. }
  32.  
  33. //void MyGraphicsView::dropEvent(QGraphicsSceneDragDropEvent *event)
  34. //{
  35. // event->accept();
  36. // qDebug("here");
  37. //}
  38.  
  39. void MyGraphicsView::dropEvent(QDropEvent *event)
  40. {
  41. qDebug("here"); // I NEVER GET TO HERE
  42. event->accept();
  43. }
  44.  
  45. int main(int argc, char *argv[])
  46. {
  47. QApplication app(argc, argv);
  48. QMainWindow window;
  49.  
  50. MyGraphicsView *view = new MyGraphicsView(scene);
  51. view->setAcceptDrops(true);
  52.  
  53. window.setCentralWidget(view);
  54. window.resize(640, 480);
  55. window.setAcceptDrops(true);
  56. window.show();
  57.  
  58. return app.exec();
  59. }
To copy to clipboard, switch view to plain text mode