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. Event when the QMouseMoveEvent is finished (released)?
Forum Updated to NodeBB v4.3 + New Features

Event when the QMouseMoveEvent is finished (released)?

Scheduled Pinned Locked Moved Solved General and Desktop
qmousereleaseevqmousemoveevent
17 Posts 4 Posters 2.8k 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Is there an event when I first click, then move mouse, then release mouse, that is emitted at the last step (QMouseReleaseEvent does only occure when no movement happend)

    Or if not, how can I detect this?

    Pl45m4P J.HilkJ 2 Replies Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      QMouseReleaseEvent comes when you release the
      mouse button so why cant you use that ?

      If you think its not the last step, its due to you moving the mouse after you release.

      You should just code your app so its not important that QMouseReleaseEvent is not the last you see.
      Just check if button is pressed before doing anything in QMouseMoveEvent and then it wont matter if
      MouseRelease is not the last event.

      1 Reply Last reply
      3
      • gde23G gde23

        Is there an event when I first click, then move mouse, then release mouse, that is emitted at the last step (QMouseReleaseEvent does only occure when no movement happend)

        Or if not, how can I detect this?

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

        @gde23

        Hi,

        probably there is a better solution, but I would set a bool to true when mouse click happens, temporarily save the point as well, then compare the QPoints of mouse press and mouse release in mouseReleaseEvent and do what you want to do, if they don't match...

        But yeah, normally you dont have to do things like this. You dont need mousePress, -release and moveEvents to detect if user drags an object with the mouse. (like @mrjj said)


        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
        1
        • gde23G gde23

          Is there an event when I first click, then move mouse, then release mouse, that is emitted at the last step (QMouseReleaseEvent does only occure when no movement happend)

          Or if not, how can I detect this?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @gde23
          the problem is probably, that your Mose leaves the area of the Widget where you override the event.
          IIRC if the mouse is not inside the widget bounds, the released slot is not triggered.

          But the leaveEvent should


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Pl45m4P 1 Reply Last reply
          2
          • J.HilkJ J.Hilk

            @gde23
            the problem is probably, that your Mose leaves the area of the Widget where you override the event.
            IIRC if the mouse is not inside the widget bounds, the released slot is not triggered.

            But the leaveEvent should

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

            @J-Hilk

            You can experience this behavior in some programs, where you dont expect such unhandled events.
            (If you drag something with mouse and leave the window or drag-area, the item is still stuck to your mouse, virtually. So when you enter the area / window again somewhere else, the item moved around the area and flies in at the position where the mouse has entered)
            In some cases it is useful, in some cases it can be annoying :)


            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
            0
            • gde23G Offline
              gde23G Offline
              gde23
              wrote on last edited by
              #6

              QMouseReleaseEvent() is not called in my case.
              Some more details: The widget is a TitelBarWidget which is set on a QDockWidget.
              What I want to detect is when it has been moved (click titelbarwidget, move around, release mousue)
              So maybee this is not a MouseMoveEvent but a MoveEvent?

              Pl45m4P 1 Reply Last reply
              0
              • gde23G gde23

                QMouseReleaseEvent() is not called in my case.
                Some more details: The widget is a TitelBarWidget which is set on a QDockWidget.
                What I want to detect is when it has been moved (click titelbarwidget, move around, release mousue)
                So maybee this is not a MouseMoveEvent but a MoveEvent?

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

                @gde23

                mouseReleaseEvent should be triggered, if you release the mouse button. It depends where you release the mouse.

                @gde23 said in Event when the QMouseMoveEvent is finished (released)?:

                So maybee this is not a MouseMoveEvent but a MoveEvent?

                MoveEvent is triggered, when you move the whole item or widget. That means, that you need to actually move the titlebar widget around on its parent window...

                Do you want to drag / move something inside your QDockWidget or is it all about detecting the movement of the QDockWidget window itself (then you can indeed use the moveEvent)?
                https://doc.qt.io/archives/qt-4.8/qwidget.html#moveEvent


                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
                0
                • gde23G Offline
                  gde23G Offline
                  gde23
                  wrote on last edited by
                  #8

                  Ok, I did not know about MoveEvent.

                  What I want to do: By grabbing the titlebarwidget the whole widget is moved. This works.
                  However at the end of the move I want to update it (not all the time during move)
                  So I am searching for how to detect the end of the movement (when the mouse is released after moving)

                  Pl45m4P 1 Reply Last reply
                  0
                  • gde23G gde23

                    Ok, I did not know about MoveEvent.

                    What I want to do: By grabbing the titlebarwidget the whole widget is moved. This works.
                    However at the end of the move I want to update it (not all the time during move)
                    So I am searching for how to detect the end of the movement (when the mouse is released after moving)

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

                    @gde23

                    You can combine the mousePressEvent and mouseReleaseEvent from your titlebar widget (The mouse stays within titlebar boundings during the movement, correct? Because it's standard dock window dragging behavior, with the only difference that you replaced the titlebar widget with a custom one?!) with the moveEvent from your QDockWidget.

                    void TitleBarWidget::mousePressEvent(QMouseEvent *event)
                    {
                      m_aboutToMove = true;
                    
                    }
                    
                    void TitleBarWidget::mouseReleaseEvent(QMouseEvent *event)
                    {
                    
                    if(m_hasMoved)
                    {
                     // UPDATE, send signal to update content
                    // reset m_hasMoved afterwards
                    }
                      m_aboutToMove = false;
                    
                    }
                    
                    void YourDockWidget::moveEvent(QMoveEvent *event)
                    {
                    
                    if(m_aboutToMove)
                    {
                      m_hasMoved = true; // you could send a signal to titlebar widget and write a public function to notify the titlebar
                    }
                    }
                    

                    Of course you can not access all the boolean from both classes directly... You'll need to write setters / getters or send signals.
                    It is just an example or idea how it can be done :)


                    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
                    1
                    • gde23G Offline
                      gde23G Offline
                      gde23
                      wrote on last edited by gde23
                      #10

                      The mouse stays inside the titlebar (since it is moves along with it) and yes, I only replaced the titelbarwidget with my own version by setTitelBarWidget().

                      However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.

                      Pl45m4P 1 Reply Last reply
                      0
                      • gde23G gde23

                        The mouse stays inside the titlebar (since it is moves along with it) and yes, I only replaced the titelbarwidget with my own version by setTitelBarWidget().

                        However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.

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

                        @gde23 said in Event when the QMouseMoveEvent is finished (released)?:

                        However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.

                        Which mouseReleaseEvent do you use? From titlebar widget or from your dockwidget


                        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
                        1
                        • gde23G Offline
                          gde23G Offline
                          gde23
                          wrote on last edited by
                          #12

                          From the titlebar

                          J.HilkJ 1 Reply Last reply
                          0
                          • gde23G gde23

                            From the titlebar

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #13

                            @gde23
                            we won't get much further, until you post a minimal reproducible example.


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            gde23G 1 Reply Last reply
                            1
                            • J.HilkJ J.Hilk

                              @gde23
                              we won't get much further, until you post a minimal reproducible example.

                              gde23G Offline
                              gde23G Offline
                              gde23
                              wrote on last edited by
                              #14

                              @J-Hilk

                              Here some code:

                              First The dockwidget gets a titlebar widget:

                              QDockWidget* dock = new QDockWidget(this); 
                              titleBarWidget = new MyTitleBarWidget(dock);
                              dock->setTitleBarWidget(titleBarWidget);
                              

                              The tiltebarwidget is just a QWidget with one single method added

                              void MyTitleBarWidget::mouseReleaseEvent(QMouseEvent *event)
                              {
                                  std::cout << "mouse Released" << std::endl;
                                  QWidget::mouseReleaseEvent(event);
                              }
                              

                              Now when you click the titlebar and release it without moving the output is printed.
                              However when you click it, then move around and then release it is not printed to std out.

                              J.HilkJ 1 Reply Last reply
                              0
                              • gde23G gde23

                                @J-Hilk

                                Here some code:

                                First The dockwidget gets a titlebar widget:

                                QDockWidget* dock = new QDockWidget(this); 
                                titleBarWidget = new MyTitleBarWidget(dock);
                                dock->setTitleBarWidget(titleBarWidget);
                                

                                The tiltebarwidget is just a QWidget with one single method added

                                void MyTitleBarWidget::mouseReleaseEvent(QMouseEvent *event)
                                {
                                    std::cout << "mouse Released" << std::endl;
                                    QWidget::mouseReleaseEvent(event);
                                }
                                

                                Now when you click the titlebar and release it without moving the output is printed.
                                However when you click it, then move around and then release it is not printed to std out.

                                J.HilkJ Offline
                                J.HilkJ Offline
                                J.Hilk
                                Moderators
                                wrote on last edited by J.Hilk
                                #15

                                @gde23
                                this,
                                https://github.com/DeiVadder/QDockWidget-Test-111758
                                is a minimal reproducible example, and I can indeed reproduce it,

                                as soon as the Docking mechanism is triggered(detach), the released signal is no longer emitted.

                                I would consider this a bug, but I haven't checked the source code to see, if its intended or not.


                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                gde23G 1 Reply Last reply
                                2
                                • J.HilkJ J.Hilk

                                  @gde23
                                  this,
                                  https://github.com/DeiVadder/QDockWidget-Test-111758
                                  is a minimal reproducible example, and I can indeed reproduce it,

                                  as soon as the Docking mechanism is triggered(detach), the released signal is no longer emitted.

                                  I would consider this a bug, but I haven't checked the source code to see, if its intended or not.

                                  gde23G Offline
                                  gde23G Offline
                                  gde23
                                  wrote on last edited by
                                  #16

                                  @J-Hilk Thanks a lot for the help. I will try to think of some other solution then.

                                  1 Reply Last reply
                                  0
                                  • gde23G Offline
                                    gde23G Offline
                                    gde23
                                    wrote on last edited by
                                    #17

                                    I finally found a method that works, that I want so share:

                                    void myWidget::moveEvent(QMoveEvent *event)
                                    {
                                        Qt::MouseButtons mouse = qApp->mouseButtons();
                                        if(mouse != Qt::LeftButton)
                                        {
                                            std::cout << "move end" << std::endl;
                                        }
                                    }
                                    

                                    If you check the mouse status in the moveEvent(), on the last move event the mouse will not be pressed anymore, which is kind of like a mouse release event. At least it works for me at the moment.

                                    1 Reply Last reply
                                    3

                                    • Login

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