I want to implement a drag and drop functionality between two custom widgets. My understanding from this question is that I cannot use the built-in drag and drop functionality that e.g. buttons would provide, but that I need to implement mouseReleaseEvent
and mousePressEvent
handlers manually.
My specific goal is as follows: I have widgets of type Widget1
and Widget2
, and I want that when Widget1
is dragged onto Widget2
, a certain action is performed. I therefore implemented the mousePressEvent
of Widget1
and the mouseReleaseEvent
of Widget2
.
class Widget1(QWidget):
...
def mousePressEvent(self, event):
print("Press")
class Widget2(QWidget):
...
def mouseReleaseEvent(self, event):
print("Release")
While "Press"
is printed whenever I click on Widget1
, "Release"
is printed only after clicking on Widget2
. That is, the release event is called for the same item that was clicked. How do I execute an action for the widget that the mouse was over at release?