Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drag and Drop Using QGraphicsView/QGraphicsScene and QGraphicsItem
Qt 6.11 is out! See what's new in the release blog

Drag and Drop Using QGraphicsView/QGraphicsScene and QGraphicsItem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jon2718
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved