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. mouseReleaseEvent not called when the mouse is released under certain circumstances

mouseReleaseEvent not called when the mouse is released under certain circumstances

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 4.5k 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.
  • K Offline
    K Offline
    Kerndog73
    wrote on last edited by Kerndog73
    #1

    I had a radio button that was working unreliably with a trackpad. Clicking the trackpad or clicking the mouse always toggles the radio button. However, tapping the trackpad doesn't seem to work every time. So I wrote an MCVE:

    #include <iostream>
    #include <QtGui/qpainter.h>
    #include <QtWidgets/qmainwindow.h>
    #include <QtWidgets/qapplication.h>
    #include <QtWidgets/qabstractbutton.h>
    
    class Button final : public QAbstractButton {
    public:
      explicit Button(QWidget *parent)
        : QAbstractButton{parent} {
        setToolTip("Tooltip");
        setCheckable(true);
        setFixedSize(200, 200);
      }
    
    private:
      void paintEvent(QPaintEvent *) override {
        QPainter painter{this};
        painter.fillRect(rect(), isChecked() ? Qt::red : Qt::blue);
      }
      
      void mousePressEvent(QMouseEvent *event) override {
        std::cout << "Down\n";
        QAbstractButton::mousePressEvent(event);
      }
      
      void mouseReleaseEvent(QMouseEvent *event) override {
        std::cout << "Up\n";
        QAbstractButton::mouseReleaseEvent(event);
      }
    };
    
    int main(int argc, char **argv) {
      QApplication app{argc, argv};
      QMainWindow window;
      window.setFixedSize(200, 200);
      Button button{&window};
      window.show();
      return app.exec();
    }
    

    I found two situations where only the mouse-press event is received so the radio isn't toggled (because it listens for mouse up). Clicking on the desktop (so that the window loses focus) then clicking on the button only triggers mouse-press. Hovering over the button and then clicking when the tooltip appears only triggers mouse-press. Note that by "click" I mean "tap the trackpad".

    It seems odd to me that only one of the [mouse-press, mouse-release] pair is received. A workaround for this that works fine in my situation is this:

    void mousePressEvent(QMouseEvent *event) override {
      if (event->button() == Qt::LeftButton) {
        toggle();
      }
    }
      
    void mouseReleaseEvent(QMouseEvent *) override {}
    

    Is this just a quirk of the OS (macOS Mojave on a 2013 MacBook Air) or does this have something to do with Qt (5.12.3)?

    KillerSmathK 1 Reply Last reply
    0
    • K Kerndog73

      I had a radio button that was working unreliably with a trackpad. Clicking the trackpad or clicking the mouse always toggles the radio button. However, tapping the trackpad doesn't seem to work every time. So I wrote an MCVE:

      #include <iostream>
      #include <QtGui/qpainter.h>
      #include <QtWidgets/qmainwindow.h>
      #include <QtWidgets/qapplication.h>
      #include <QtWidgets/qabstractbutton.h>
      
      class Button final : public QAbstractButton {
      public:
        explicit Button(QWidget *parent)
          : QAbstractButton{parent} {
          setToolTip("Tooltip");
          setCheckable(true);
          setFixedSize(200, 200);
        }
      
      private:
        void paintEvent(QPaintEvent *) override {
          QPainter painter{this};
          painter.fillRect(rect(), isChecked() ? Qt::red : Qt::blue);
        }
        
        void mousePressEvent(QMouseEvent *event) override {
          std::cout << "Down\n";
          QAbstractButton::mousePressEvent(event);
        }
        
        void mouseReleaseEvent(QMouseEvent *event) override {
          std::cout << "Up\n";
          QAbstractButton::mouseReleaseEvent(event);
        }
      };
      
      int main(int argc, char **argv) {
        QApplication app{argc, argv};
        QMainWindow window;
        window.setFixedSize(200, 200);
        Button button{&window};
        window.show();
        return app.exec();
      }
      

      I found two situations where only the mouse-press event is received so the radio isn't toggled (because it listens for mouse up). Clicking on the desktop (so that the window loses focus) then clicking on the button only triggers mouse-press. Hovering over the button and then clicking when the tooltip appears only triggers mouse-press. Note that by "click" I mean "tap the trackpad".

      It seems odd to me that only one of the [mouse-press, mouse-release] pair is received. A workaround for this that works fine in my situation is this:

      void mousePressEvent(QMouseEvent *event) override {
        if (event->button() == Qt::LeftButton) {
          toggle();
        }
      }
        
      void mouseReleaseEvent(QMouseEvent *) override {}
      

      Is this just a quirk of the OS (macOS Mojave on a 2013 MacBook Air) or does this have something to do with Qt (5.12.3)?

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by KillerSmath
      #2

      @Kerndog73
      The event is received.
      By default, the QAbstractButton just perform the nextCheckState action after it is released and the release pos contain the Button Pos.

      mouseReleaseEvent() -> click() -> nextCheckState()

      Note: -> means the order of calls.

      You can confirm it on source code.

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      K 1 Reply Last reply
      0
      • KillerSmathK KillerSmath

        @Kerndog73
        The event is received.
        By default, the QAbstractButton just perform the nextCheckState action after it is released and the release pos contain the Button Pos.

        mouseReleaseEvent() -> click() -> nextCheckState()

        Note: -> means the order of calls.

        You can confirm it on source code.

        K Offline
        K Offline
        Kerndog73
        wrote on last edited by Kerndog73
        #3

        @KillerSmath I understand that QAbstractButton listens to mouseReleaseEvent (I mentioned that in my original post). What I am saying is that mouseReleaseEvent isn’t called under very specific circumstances.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kerndog73
          wrote on last edited by
          #4

          Is anyone able to reproduce this on a mac?

          J.HilkJ 1 Reply Last reply
          0
          • K Kerndog73

            Is anyone able to reproduce this on a mac?

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Kerndog73
            Just tested it, can't reproduce it.
            Up and Down come in all cases, with prior focus or without, with tooltip or without.

            Tested with trackpad and Magic Trackpad on macOS 10.14.4, 2015 MacBookPro


            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.

            K 1 Reply Last reply
            0
            • K Offline
              K Offline
              Kerndog73
              wrote on last edited by
              #6

              I'm running 10.14.3 so maybe this was a minor bug that was fixed in 10.14.4. I'll mark this thread as solved if the software update fixes the problem.

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

                @Kerndog73
                Just tested it, can't reproduce it.
                Up and Down come in all cases, with prior focus or without, with tooltip or without.

                Tested with trackpad and Magic Trackpad on macOS 10.14.4, 2015 MacBookPro

                K Offline
                K Offline
                Kerndog73
                wrote on last edited by
                #7

                @J.Hilk Updating to 10.14.4 didn't solve the problem. It's frustrating that I seem to be the only one having this problem. Maybe we're not doing the same thing? In case I wasn't clear enough, I'm tapping the trackpad. I'm not clicking the diving board trackpad (not hearing an audible "click").

                It looks like I'll have to keep using my workaround. Are there any problems with the workaround? Is there a better way?

                J.HilkJ 1 Reply Last reply
                0
                • K Kerndog73

                  @J.Hilk Updating to 10.14.4 didn't solve the problem. It's frustrating that I seem to be the only one having this problem. Maybe we're not doing the same thing? In case I wasn't clear enough, I'm tapping the trackpad. I'm not clicking the diving board trackpad (not hearing an audible "click").

                  It looks like I'll have to keep using my workaround. Are there any problems with the workaround? Is there a better way?

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @Kerndog73
                  oh,
                  do you have "tab for click" active ?
                  I do not, and I remember an other poster in this forum, reporting inconsistencies with tab to click on macOS and the later versions of Qt!


                  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.

                  K 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @Kerndog73
                    oh,
                    do you have "tab for click" active ?
                    I do not, and I remember an other poster in this forum, reporting inconsistencies with tab to click on macOS and the later versions of Qt!

                    K Offline
                    K Offline
                    Kerndog73
                    wrote on last edited by Kerndog73
                    #9

                    @J.Hilk Yes, I have tap-to-click enabled.

                    0_1556866004208_Screen Shot 2019-05-03 at 16.15.45.png

                    (Damn! I love that window screenshot feature! The drop-shadow looks so cool!)

                    Do you have a link to the other thread where this problem was mentioned? It's not that big of a deal though. I don't really mind overriding mousePressEvent and calling toggle (or even just ignoring the problem). After reading the docs, I should probably call nextCheckState instead.

                    J.HilkJ 1 Reply Last reply
                    0
                    • K Kerndog73

                      @J.Hilk Yes, I have tap-to-click enabled.

                      0_1556866004208_Screen Shot 2019-05-03 at 16.15.45.png

                      (Damn! I love that window screenshot feature! The drop-shadow looks so cool!)

                      Do you have a link to the other thread where this problem was mentioned? It's not that big of a deal though. I don't really mind overriding mousePressEvent and calling toggle (or even just ignoring the problem). After reading the docs, I should probably call nextCheckState instead.

                      J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @Kerndog73 said in mouseReleaseEvent not called when the mouse is released under certain circumstances:

                      Do you have a link to the other thread where this problem was mentioned?

                      that took me an abyssal amount of time to dig up.
                      But here you go

                      https://forum.qt.io/topic/99808/no-mouse-release-event-anymore-on-tap-macos-qt-5-12


                      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.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        S Jackson
                        wrote on last edited by
                        #11

                        Apologies for posting to an old thread, but I wanted to add a clue that might be helpful.

                        I am seeing this behavior in a Qt project of my own, but only on Mac laptops from 2015 and later (specifically, models with a force touch trackpad), when "Tap to Click" is enabled. On earlier laptops without a force touch trackpad, the bug does not present.

                        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