How to detect Drops outside of the target
-
Let me explain my issue with a simplified explanation:
I want to transfer something from
Widget AtoWidget Bvia drag and drop.So far so good I understand how to do it.
Just one issue I face. I want to take something out of
Widget Aas soon as the drag is started (Before it reaches its destination). That something should get dropped onWidget B.If the drop is released on the way (outside of
Widget B) the contend should be transferred back toWidget A.How can I achieve that?
To give some more details:
Widget AandWidget Bare both derrived fromQGraphicsWidgetplaced into aQGraphicsScene.I implemented all the drag and drop operations in
Widget AandWidget B.My idea would be:
Derrive
QGraphicsSceneitself and implementdropEventthere.Is that the right way or is there a better one?
-
Hi,
Shouldn't you rather hide it until done and just show it again on drop failure ?
-
Do you implement your own dnd handlers or use the Qt default ones?
-
I use
QDropwithQMimeData.And true in the real app something just gets hidden in the
Widget A. But how to i report to it that the drop failed? -
My question was more - how do you begin the drag operation? Normally you call QDrag::exec() or something similar which returns the drop action used.
-
@Christian-Ehrlicher said in How to detect Drops outside of the target:
QDrag::exec()
A yes i call
QDrag::exec()inmouseMoveEventofWidget A -
As @Christian-Ehrlicher already suggested, check the result of exec and act accordingly.
-
I checked the result like this:
// do change here // do the drag auto result = drag->exec(); if (result == Qt::IgnoreAction) { // revert change here }So that should be it