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.
Currently I have an idea. After I start the first drag, when my drag reaches a certain point, I cancel the first drag then I restart a new drag with a new image.
I do this in dragMoveEvent
. I'm able to start a new drag with a new image. But I seem to be unable to cancel the first drag. I find that the the previous drag/drop action is still being performed.
Anyone could suggest:
if (event->mimeData()->hasText())
{
if (need_to_change_pixmap())
{
event->setDropAction(Qt::IgnoreAction);
change_pixmap_restart_drag();
}
else
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
}
else
{
event->ignore();
}
The change_pixmap_restart_drag
function just do start drag.
According to Qt's documentation, you can't change the pixmap once the dragging has started.
Qt uses:
setGrabMouse
is used to receive mouse events, since the widget is not directly under the mouse.SetCursor
on Windows, with a copy of the pixmap where the cursors for each action has been painted in the corner.SetDragImageWithCGImage
on Mac, but needs a DragRef
object which is declared as an inaccessible local variable in qdnd_mac.mm.You could try to use the X11 method on all platforms, or use SetCursor
if you only plan to deploy your application on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With