Important: Please read the Qt Code of Conduct -

mouseReleaseEvent not called when the mouse is released under certain circumstances

  • 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 {
      explicit Button(QWidget *parent)
        : QAbstractButton{parent} {
        setFixedSize(200, 200);
      void paintEvent(QPaintEvent *) override {
        QPainter painter{this};
        painter.fillRect(rect(), isChecked() ? Qt::red : Qt::blue);
      void mousePressEvent(QMouseEvent *event) override {
        std::cout << "Down\n";
      void mouseReleaseEvent(QMouseEvent *event) override {
        std::cout << "Up\n";
    int main(int argc, char **argv) {
      QApplication app{argc, argv};
      QMainWindow window;
      window.setFixedSize(200, 200);
      Button button{&window};;
      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) {
    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)?

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

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

  • Is anyone able to reproduce this on a mac?

  • Moderators

    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

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

  • @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?

  • Moderators

    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!

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

  • Moderators

    @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

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

Log in to reply