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
    {
    Q_OBJECT
    public:
    GraphicsView(View *v) : QGraphicsView(), view(v) { }

    protected:
    #ifndef QT_NO_WHEELEVENT
    void wheelEvent(QWheelEvent *);
    #endif

    private:
    View *view;

    protected:

    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?

    Thanks.

    -Jon


  • Lifetime Qt Champion

    Hi,

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.