View Full Version : Handle Drag & Drop Events with QGraphicsItem [SOLVED]

7th February 2007, 16:19
Ok, Problem found : I had to start the event with a QDrag of course :D
Now, it works fine!


I have a little problem with subclassing QGraphicsItem : everything works fine, bounding box, painting, etc, excepted that I cannot catch drag & drop events...

My Item is part of a QGraphicsScene, rendered with a QGraphicsView, nothing special really...
I have reimplemented the 3 protected functions for drag (dragEnter, dragMove, dropEvent..), but nothing happens.

It seems that events aren't dispatched by the scene...I followed the Qt Drag And Drop Robot Example, and it works perfectly there...Any idea ?



11th December 2009, 13:51

I'm having the same problem but I don't understand what he wanted to say with "I had to start the event with a QDrag of course".

I have a QGraphicsScene, QGraphics view and my items are moved perfectly by drag&drop... but the events are not catched.

All the subclassed events called its parent event at the end, so I'm a bit lost.


Edit: I forgot to say I already added setAcceptDrops(true)

13th July 2010, 19:05
I know this thread is old but I found it through Google and just wanted to help people that stumble upon this thread.

So if you want to Drag a QGraphicsItem you need to signal Qt when you want a Drag-Event to be started.
So what guilugi forgot was to Generate a QDrag Object to let Qt know that a Drag event started.

This is the example from the dragdroprobot-example:

void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
.length() < QApplication::startDragDistance()) {

QDrag *drag = new QDrag(event->widget());
QMimeData *mime = new QMimeData;
/* . . . */
/* . . . */