PDA

View Full Version : How to catch items dropped out of scenes?



Gourmet
2nd February 2015, 12:19
If user takes item on scene - then I "take" it out. While user drags it - item flies over application in QDrag object. When user drops it somewhere outside reasonable scene - I need return item to initial position where it was taken. But I do not see how do that. Only one thing I found - QDrag emits targetChanged() signal when drag exits outside application. But I need catch DROP event outside app. How do that?? Sure entire event processing can be implemented in app but this does not look Qt-like. Is it a huge groove in Qt D&D engine or I just missed something?

wysota
2nd February 2015, 12:42
If the drop doesn't work, the place where the drag starts should receive information about it as a result of QDrag::exec().

Gourmet
2nd February 2015, 12:49
If the drop doesn't work, the place where the drag starts should receive information about it as a result of QDrag::exec().

And what? QDrag::exec() returns value of Qt::DropActions enum which is unusable in this case. And I call drag->exec(); in implementation of mouseMoveEvent(QGraphicsSceneMouseEvent *event) in draggable item but not in scene.

wysota
2nd February 2015, 13:30
And what? QDrag::exec() returns value of Qt::DropActions enum which is unusable in this case.
Why? If Qt::IgnoreAction is returned then there was no drop.


And I call drag->exec(); in implementation of mouseMoveEvent(QGraphicsSceneMouseEvent *event) in draggable item but not in scene.
I don't see how that matters.

Gourmet
2nd February 2015, 17:45
Ok, this works. But looks not so... straight. I'd better prefer signal QDrag::droppedTo( QWidget*, QPointF );

wysota
2nd February 2015, 18:17
That would be useless if the drop occurred outside your app. Or was canceled.

Gourmet
2nd February 2015, 18:55
Otside the app QWidget* would be 0 with QPointF representing absolute screen position. This would be enough and easy to use.

wysota
2nd February 2015, 22:24
Maybe in your particular case yes but I don't see what benefit it would bring to know the screen coordinates of the drop. Especially if more than one application window occupies the same screen spot. Basically it is the target application that handles the drop, the source should only know whether the semantics is to let go of the resource or not.