PDA

View Full Version : QDrag - Change the image display while dragging



chkong
13th October 2011, 02:41
I started a drag with image.


QDrag* drag = new(QDrag)(this);
drag->setPixmap(*pixmap);
drag->exec(Qt::CopyAction | Qt::MoveAction);

I want to change the image display when my drag reach certain point in the widget. Is there anyway to retrieve the drag object so that I could change the image?

fullmetalcoder
19th October 2011, 21:30
The QDrag API explicitely states that the pixmap can only be set before starting the drag operation. However a cursory look at Qt sources (I'm using Qt 4.7 branch from gitorious as a reference) seems to indicate that the pixmap is actually updated on every drag move event so the following *could* work :


make the QDrag object a member of your widget (not strictly necessary, the important point is that it is accessible from your widget's event handlers)
do whatever position check you need in your widget's dragMoveEvent and call setPixmap on the QDrag object as needed