[SOLVED] Drag & drop, retrieving a drop signal ?
Quite a rough question I am dealing with for 2 days now. I have an application divided in 2 parts. First one is a 3D anatomical human model, second one is a Qt Widget with mini games.
My objective consists of being able to grab human organs from the left panel (3D model), make them invisible in the model while in drag & drop, put a 2D image as the cursor pixmap, and then drop it on the right panel (Qt).
If I drop it on the correct widget (a custom DropLabel), the game continues correctly, but if I drop it on a wrong widget (like a normal label or the "return" button for example) I should be able to bring the 3D model of the organ back in visible mode.
Here is my problem : Everything of what I said above is made, except one thing : I dont find any way to catch an event when dropping the object on a wrong widget. The only thing i figured out would be to remake every class (like a custom QLabel) that accepts drops and from there I could manage to tell my 3D model to update the organ visibility.
But, this "fix" seems quite wrong to me. What happens if I have like 50 different widgets on the right ? Do I have to make a custom class for EACH ONE of these just for that stupid drag & drop functionnality ? This makes me feel I am doing something wrong, but I have no idea what I have forgotten :/
Any help on this topic would be much appreciated
It would help to see some code but, based on what you said, you should search about "event filtering":http://qt-project.org/doc/qt-5/qobject.html#eventFilter. You can use it to receive events without subclassing objects.
Hi and welcome to devnet,
If you are using QDrag to accomplish this, you should check the return value of exec, from there you can react accordingly
Thanks for the answer, that was much appreciated.
to be honest @tilsitt, I didnt really know which part of the code I could show you cause what I am trying to do seemed quite trivial.
Anyway, your answer was nice, and I already use this eventFilter for my 3D view, but it happened that it was working on the Qt part (or I did just fail at using it).
But the answer came from SGaist. I don't know how I failed at looking this return action from QDrag, but as soon as I have seen that exec was a blocking function, I understood that it would give back the resulting drop information (even if I read it carefully, I did not take that in consideration ...)
So, When my returned action is = to Qt::IgnoreAction, I just re-update my 3D content and show my organ again.
This works like a charm \o/ Again, thanks guys for the help.