0

I need to simulate drag and drop in Qt, but I'm facing a problem. Here is the simplified version of the problem: enter image description here

here you can see the action I took. I pressed the mouse in the area of parent widget and moved it to a child widget, keeping pressing, I did not release the mouse until it is moved into the child Widget. However, I found that the child widget could not capture the mouse release event when I released the mouse. (Actually, I found it was not only mouse release event, but also any other mouse event which was supposed to happen when the mouse was in the child widget)

Could someone give me a simple solution to do this? Maybe It is because the widget structure in my project is quite complicated so there is something wrong stops the transfer of the mouse event.

  • 2
    Amazing drawing, but before you are bombared with comments asking for [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Please provide the code that you have written so far. It gives a starting point to other people to start thinking, and get up and running faster. – akaAbdullahMateen Jul 10 '22 at 20:16
  • 2
    Do not implement drag and drop using `mouseReleaseEvent` but implement it via proper drag and drop events which are designed for this purpose. You are trying to reinvent a wheel and you took a very wrong direction. See https://doc.qt.io/qt-5/dnd.html – HiFile.app - best file manager Jul 10 '22 at 21:16

1 Answers1

0

Try to accept mouse release event in parent widget, calculate mouse position, compare to child widget, and notify child widget Qt - Determine absolute widget and cursor position. Or use QDrag and QMimeData if you want to pass data.

Robin L
  • 125
  • 8