Important: Please read the Qt Code of Conduct -

Moving a widget in Drag&Drop

  • Hello Gurus,

    I'm trying but no luck so far. It would be great if anyone could direct me to a right way. :)

    Now I'm trying drag&drop capability between multiple QMainWindows.
    I want to drag a widget on a QMainwindow to another widget on another QMainwindow by visually moving the dragged widget, that is, drag&drop.

    Just to move widget, I reimplemented mouseMoveEvent/mousePressEvent/mouseReleasedEvent and it worked, but if I included the creation of Qdrag object in the mousePressEvent, I noticed I couldn't receive mouseReleasedEvent. I guess it's because dropEvent overwrites it... :<

    Is there a way to coexist drag&drop and move functionalities?

    Many thanks in advance for your help.

  • @ShinSat Looks like mouseMoveEvent is not available during Qdrag.MoveAction... :<


  • Lifetime Qt Champion


    Can you show a minimal compilable example that shows what you are trying to do ?

  • @SGaist My scenario is some thing like that a widget moves in mouseMoveEvent and QDrag object is created in mousePressEvent.

    def mousePressEvent(self):
        mime = QMimeData()
        mime.setData( ... )
       qdrag = QDrag()
    def mouseMoveEvent(self, event):
        # calculate the position moving to
       self.mvoe(x, y)

    The problem is mouseMoveEvent is not ivoked during Qt.MoveAction.
    How can I deal with that?


  • @ShinSat Update:
    Now I'm changing my approach and testing it.
    Actually, I isolated drag&drop and moving the widget. In other words, without dropEvent, the destination widget accepts the mouseReleaseEvent when it's under the cursor. The source widget drops into the destination. The advantage of this approach doesn't require QDrag object.


Log in to reply