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. Moving a widget in Drag&Drop

Moving a widget in Drag&Drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 890 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
    ShinSat
    wrote on 9 Nov 2017, 04:45 last edited by
    #1

    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.
    Sat

    S 1 Reply Last reply 9 Nov 2017, 06:10
    0
    • S ShinSat
      9 Nov 2017, 04:45

      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.
      Sat

      S Offline
      S Offline
      ShinSat
      wrote on 9 Nov 2017, 06:10 last edited by
      #2

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

      Sat

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 9 Nov 2017, 22:59 last edited by
        #3

        Hi,

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

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

        S 1 Reply Last reply 11 Nov 2017, 11:29
        1
        • S SGaist
          9 Nov 2017, 22:59

          Hi,

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

          S Offline
          S Offline
          ShinSat
          wrote on 11 Nov 2017, 11:29 last edited by
          #4

          @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()
             ....
             qdrag.exec(Qt.MoveAction)
             ...
          
          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?

          Sat

          S 1 Reply Last reply 11 Nov 2017, 13:27
          0
          • S ShinSat
            11 Nov 2017, 11:29

            @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()
               ....
               qdrag.exec(Qt.MoveAction)
               ...
            
            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?

            Sat

            S Offline
            S Offline
            ShinSat
            wrote on 11 Nov 2017, 13:27 last edited by ShinSat 11 Nov 2017, 13:28
            #5

            @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.

            Sat

            1 Reply Last reply
            0

            4/5

            11 Nov 2017, 11:29

            • Login

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