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. Stick a widget to the mouse while Drag N Drop?
Forum Updated to NodeBB v4.3 + New Features

Stick a widget to the mouse while Drag N Drop?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    m1212e
    wrote on last edited by m1212e
    #1

    Hey,

    I'm trying to make a widget Drag N Dropable. Works fine so far, all the events get fired properly. But I want a cool "animated" drag widget which sticks to the mouse as the user is dragging. I thought maybe the best way is to start a thread which repeatedly sets the widget to the cursor position as soon as the widget is clicked and dragged.
    I'd start it in the mouseMoveEvent(QMouseEvent *e) and would set the stop flag in the dropEvent(QDropEvent *e). So I havent looked at the threads yet and if you got any tips there I would appreciate it, but my more important problem is that I don't know how to set a widget absolutely to a position. It should be ripped out of it's layout and then be displayed above every other widget, as long as the drag goes.
    Is that the way to approach it? Or am I missing a thing here?

    Alternatively I thought about just setting the cursor to a corresponding Pixmap, but that would prevent any animations and seems a bit hacky to me.

    Thanks for any suggestions :D

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

      Hi,

      If you are creating your own QDrag object then you can use QDrag::setPixmap and put there the rendered version of your widget.

      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
      3
      • M Offline
        M Offline
        m1212e
        wrote on last edited by m1212e
        #3

        Okay, thank you, that kinda works.
        GridDrag.png
        But now I've got this ugly background and the hover effect is captured when I start dragging it. I probably need to store a not interacted pixmap in my object when it gets created so I haven't got the hover effect in my render. But do you have an idea how to get rid of the background? I've found a thread, you contributed to it, but I couldn't really understand what I have to do..
        Thanks for your help!

        Edit: So that worked for me. Got rid of the hover effect by simply rendering the widget in it's show event and storing the pixmap inside a member. Still got that background tho.

        Pl45m4P 2 Replies Last reply
        0
        • M m1212e

          Okay, thank you, that kinda works.
          GridDrag.png
          But now I've got this ugly background and the hover effect is captured when I start dragging it. I probably need to store a not interacted pixmap in my object when it gets created so I haven't got the hover effect in my render. But do you have an idea how to get rid of the background? I've found a thread, you contributed to it, but I couldn't really understand what I have to do..
          Thanks for your help!

          Edit: So that worked for me. Got rid of the hover effect by simply rendering the widget in it's show event and storing the pixmap inside a member. Still got that background tho.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @m1212e said in Stick a widget to the mouse?:

          Still got that background tho

          Have you tried to set a translucent background before rendering your widget? I think, this is what the OP in your linked thread also did

          setAttribute(Qt::WA_TranslucentBackground);
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          3
          • M Offline
            M Offline
            m1212e
            wrote on last edited by
            #5

            Must have missed it. Thank you very much! Works fine now :D

            1 Reply Last reply
            2
            • M m1212e

              Okay, thank you, that kinda works.
              GridDrag.png
              But now I've got this ugly background and the hover effect is captured when I start dragging it. I probably need to store a not interacted pixmap in my object when it gets created so I haven't got the hover effect in my render. But do you have an idea how to get rid of the background? I've found a thread, you contributed to it, but I couldn't really understand what I have to do..
              Thanks for your help!

              Edit: So that worked for me. Got rid of the hover effect by simply rendering the widget in it's show event and storing the pixmap inside a member. Still got that background tho.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @m1212e said in Stick a widget to the mouse?:

              but I couldn't really understand what I have to do

              The code sample posted by the OP shows a section from a version control system (like Git) change log file.
              The + (green background) lines indicate insertions.
              So, if you know what to look for, it takes 3 seconds, until you know what's going on there :-)
              In case you didnt know that :-)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              2

              • Login

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