View Full Version : QGraphicsItem & dragndrop

22nd September 2009, 20:10

I have successfully implemented "Attribute" class by sub classing "QGraphicsItem".
Drag n Drop between instances is working fine.
There are three things I would like to solve:

1. In dropEvent, how do you find out the source "Attribute" from which drag has started?
I am using this method, but as per the docs it won't work.

void Attribute::dropEvent(QGraphicsSceneDragDropEvent *event)
Attribute *attrib = qgraphicsitem_cast<Attribute *>(event->source());

2. As soon as drag starts I would like to draw a line from source attribute and current mouse position continuously. This is like setting up a dynamic pixmap for drag.

3. While dragging the cursor changed to Qt::ForbiddenCursor, until you are not hovering
on another "Attribute" instance. How do I hide this cursor while dragging?
In dragMoveEvent I tried setting up the cursor by using an empty pixmap but it's crashing the application

QPixmap pixmap;
drag->setDragCursor(pixmap, Qt::IgnoreAction);