Hello Again!

If you don't call the base class implementation, the scene shouldn't receive the event.
OK, so there's the problem? I see the exact opposite of this.

Shall we have a quick overview of my code -

View header file

Qt Code:
  1. class myView : public QGraphicsView
  2. {
  3. public:
  4. myView(QWidget *parent=0);
  5. protected:
  6.  
  7. void dragEnterEvent(QDragEnterEvent *event);
  8. void dropEvent(QDropEvent *event);
  9. void dragMoveEvent(QDragMoveEvent *event);
  10.  
  11. };
To copy to clipboard, switch view to plain text mode 

view methods

Qt Code:
  1. myView::myView(QWidget *parent) : QGraphicsView(parent) {
  2. // setAcceptDrops(true);
  3. // Comment the line below, and drop starts working
  4. setScene(new QGraphicsScene(this));
  5. }
  6.  
  7. void myView::dragEnterEvent(QDragEnterEvent *event) {
  8. // event->accept();
  9. qDebug() << "View: dragEnterEvent";
  10. QGraphicsView::dragEnterEvent(event);
  11. }
  12.  
  13. void myView::dropEvent(QDropEvent *event) {
  14. QPointF pnt;
  15. QPoint pos;
  16.  
  17. qDebug() << "View sees drop";
  18.  
  19. pos = event->pos();
  20. pnt = this->mapToScene( event->pos() );
  21.  
  22. if (itm = itemAt( pos ) )
  23. {
  24. qDebug("There is an item here");
  25. QGraphicsView::dropEvent(event);
  26. return;
  27. }
  28. else
  29. {
  30. qDebug("Blank area");
  31. }
  32. // Is there something underneath?
  33.  
  34. QByteArray ba = event->mimeData()->data("foo/bar");
  35. QDataStream ds(&ba, QIODevice::ReadOnly);
  36. while (!ds.atEnd()) {
  37. QString name;
  38. QString path;
  39. QString monid;
  40. MyNode * nd;
  41. ds >> name >> path >> monid;
  42. qDebug() << name << path << monid;
  43.  
  44. //
  45. // This view is inside the central widget which is in the mainwindow, so node
  46. // parent is the mainwindow so it can access the action functions. a bit
  47. // untiy huh?
  48. //
  49. if (QString("Button")==name)
  50. nd = new MyNode( (QWidget*)(this->parent())->parent(), name, path, monid, MyNode::BUTTON);
  51. else
  52. nd = new MyNode( (QWidget*)(this->parent())->parent(), name, path, monid, MyNode::POINT);
  53. sc = this->scene();
  54.  
  55. pnt = this->mapToScene( event->pos() );
  56. qDebug() << pnt;
  57. nd->setPos(pnt);
  58. sc->addItem(nd);
  59. }
  60. }
  61.  
  62. void myView::dragMoveEvent(QDragMoveEvent *event) {
  63. }
To copy to clipboard, switch view to plain text mode 


Scene header

Qt Code:
  1. class myScene : public QGraphicsScene
  2. {
  3. public:
  4. myScene(QObject *parent);
  5. void dropEvent(QGraphicsSceneDragDropEvent * event);
  6. void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
  7. };
To copy to clipboard, switch view to plain text mode 

scene code

Qt Code:
  1. myScene::myScene(QObject*parent): QGraphicsScene(parent)
  2. {
  3. }
  4.  
  5. void myScene::dropEvent(QGraphicsSceneDragDropEvent * event)
  6. {
  7. qDebug() << "scene: dropEvent";
  8. qDebug() << items(event->scenePos()).count();
  9.  
  10. this->setFocus(Qt::NoFocusReason);
  11.  
  12.  
  13. gi = this->itemAt( event->scenePos() );
  14.  
  15. if (gi)
  16. {
  17. qDebug() << "Scene(dropEvent); there is an item thar";
  18. gi->setFocus(Qt::NoFocusReason);
  19. gi->setSelected(true);
  20. }
  21.  
  22. QGraphicsScene::dropEvent(event);
  23. }
  24.  
  25. void myScene::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
  26. {
  27. event->acceptProposedAction();
  28.  
  29. gi = this->itemAt( event->scenePos() );
  30.  
  31. if (gi)
  32. {
  33. qDebug() << "Scene(dragEnterEvent); there is an item thar";
  34. gi->setFocus(Qt::NoFocusReason);
  35. gi->setSelected(true);
  36. }
  37.  
  38. qDebug() << "scene: dragEnterEvent";
  39. QGraphicsScene::dragEnterEvent(event);
  40. }
To copy to clipboard, switch view to plain text mode 

And finally item header

Qt Code:
  1. class MyNode : public QGraphicsItem
  2. {
  3. public:
  4. int MonId;
  5. int ValInt;
  6. int DataType;
  7. QString endnode;
  8. QString path;
  9. QString monid;
  10.  
  11. enum MimicType { LAMP, BUTTON, POINT };
  12. MimicType mimic;
  13. int EditMode;
  14.  
  15.  
  16. MyNode(QWidget * parent, QString endnode, QString path, QString monid, MimicType mt);
  17. QRectF boundingRect() const;
  18. void paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget *widget);
  19. void mousePressEvent(QGraphicsSceneMouseEvent * event);
  20. void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
  21. void dropEvent(QGraphicsSceneDragDropEvent * event);
  22. void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
  23. void dragMoveEvent(QGraphicsSceneDragDropEvent * event);
  24. void myupdate();
  25. void createActions();
  26. QAction * myAct;
  27. void passDrop(QDropEvent * event);
  28.  
  29. private slots:
  30. void doMyAct();
  31. QWidget * parent;
  32. };
To copy to clipboard, switch view to plain text mode 

and the item drag methods...

Qt Code:
  1. void MyNode::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
  2. {
  3. qDebug() << "Node: dragEnterEvent";
  4. //event->setAccepted(true);
  5. //event->accept();
  6. event->acceptProposedAction();
  7. QGraphicsItem::dragEnterEvent(event);
  8. }
  9. void MyNode::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
  10. {
  11. qDebug() << "Node: dragMoveEvent";
  12. event->accept();
  13. QGraphicsItem::dragMoveEvent(event);
  14. }
  15. void MyNode::dropEvent(QGraphicsSceneDragDropEvent * event)
  16. {
  17. qDebug() << "Node: dropEvent";
  18. QGraphicsItem::dropEvent(event);
  19. }
To copy to clipboard, switch view to plain text mode