Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Drag & drop, retrieving a drop signal ?
QtWS25 Last Chance

[SOLVED] Drag & drop, retrieving a drop signal ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NoboDie
    wrote on last edited by
    #1

    Hey everyone,

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NoboDie
          wrote on last edited by
          #4

          Hello everyone

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved