Important: Please read the Qt Code of Conduct -

mouseReleaseEvent not called only with Qt::RightButton

  • Solution
    In my case, the mouseReleaseEvent was caught by another widget because mousePressEvent with Qt::RightButton shows a menu at the clic position

    I have a Canvas class that looks like this :

    class Canvas : public QOpenGLWidget
    // [...]
    protected : 
        void mouseReleaseEvent(QMouseEvent* e) override {
            std::cout << "mouseRelease called ";
            if (e->button() == Qt::RightButton) {
                std::cout << "with right button" << std::endl;
            } else if (e->button() == Qt::LeftButton) {
                std::cout << "with left button" << std::endl;
    // [...]

    Now when I

    • left click into my canvas i get : mouseRelease called with left button
    • right click into my canvas i get nothing (the method is not called)

    I tried with both my laptop pad and my mouse, both give the same result.

    I could not reproduce the bug in a minimal example and his bug does not occur when i compile my project with Qt 5.6

    Any ideas ?


  • Lifetime Qt Champion

    You should call the base class impl of mousePress/ReleaseEvent() functions.

  • @Christian-Ehrlicher Right thank you
    It does not solve the problem though

  • Lifetime Qt Champion

    The you have to minimize your program until it works.

  • @Christian-Ehrlicher The me knows these things thank you
    I have found the issue :
    On mousePressed with RightButton, a QMenu is shown. I am afraid that the mouseRelease was then caught by the menu instead of my canvas.

Log in to reply