Important: Please read the Qt Code of Conduct -

Drag and Drop Using QGraphicsView/QGraphicsScene and QGraphicsItem

  • Hi,

    I am trying to implement and test a simple drag and drop scenario using drag and drop within the context of QGraphicsView/QGraphicsScene. I am using the 40000 Chips example from Qt as a starting point. I am simply trying to implement drag on drop when a chip is dragged in one of the views. I added the following to GraphicsView (implementation of QDragMoveEvent):

    class GraphicsView : public QGraphicsView
    GraphicsView(View *v) : QGraphicsView(), view(v) { }

    #ifndef QT_NO_WHEELEVENT
    void wheelEvent(QWheelEvent *);

    View *view;


    virtual void dragMoveEvent(QDragMoveEvent * event);


    void View::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
    qDebug() << "In dragMoveEvent";

    However, when I drag a chip around inside a view, I am not seeing that dragMoveEvent is being called. What am I doing wrong here? Shouldn't this method be called when chips are dragged within a view?



  • Lifetime Qt Champion


    If I'm not mistaken, you should be subclassing QGraphicsScene for that not QGraphicsView. The scene is where the actions happen. The view is essentially for viewing what goes on in the scene

    Hope it helps

Log in to reply