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. How to detect Drops outside of the target

How to detect Drops outside of the target

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 848 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    Let me explain my issue with a simplified explanation:

    I want to transfer something from Widget A to Widget B via 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 A as soon as the drag is started (Before it reaches its destination). That something should get dropped on Widget B.

    If the drop is released on the way (outside of Widget B) the contend should be transferred back to Widget A.

    How can I achieve that?

    To give some more details:

    Widget A and Widget B are both derrived from QGraphicsWidget placed into a QGraphicsScene.

    I implemented all the drag and drop operations in Widget A and Widget B.

    My idea would be:

    Derrive QGraphicsScene itself and implement dropEvent there.

    Is that the right way or is there a better one?

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

      Hi,

      Shouldn't you rather hide it until done and just show it again on drop failure ?

      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
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Do you implement your own dnd handlers or use the Qt default ones?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • S Offline
          S Offline
          sandro4912
          wrote on last edited by
          #4

          I use QDrop with QMimeData.

          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?

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • S Offline
              S Offline
              sandro4912
              wrote on last edited by
              #6

              @Christian-Ehrlicher said in How to detect Drops outside of the target:

              QDrag::exec()

              A yes i call QDrag::exec() in mouseMoveEvent of Widget A

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

                As @Christian-Ehrlicher already suggested, check the result of exec and act 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
                1
                • S Offline
                  S Offline
                  sandro4912
                  wrote on last edited by
                  #8

                  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

                  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