Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76914

The mouse left click release event is not called when a context menu has been closed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.12.4
    • None
    • Kubuntu 18.04 64bit / Kde plasma 5.12.7
      Build with Clang 6.0 64bit
    • Linux/X11

    Description

      The event handler mouseReleaseEvent() is not called for a mouse left click release if a context menu has been closed just before.

      It is possible to reproduce the bug in an empty Mainwindow project (as below).
      The steps are :

      1) Left click pressed
      2) Right click pressed and release (the context menu appear)
      3) Right click pressed and release somewhere else to close the menu
      4) Left click release => here the signal mouseReleaseEvent() is not called

       

       

      // mainwindow.cpp
      #include "mainwindow.h"
      #include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);    setContextMenuPolicy(Qt::CustomContextMenu);    connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
                  this, SLOT(slotShowContextMenu(const QPoint &)));
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::mousePressEvent(QMouseEvent *event)
      {
          qDebug() << "Mouse button pressed" << event->button();
      }
      
      void MainWindow::mouseReleaseEvent(QMouseEvent *event)
      {
          qDebug() << "Mouse button released" << event->button(); // => not called if a context menu has been closed before
      }
      
      void MainWindow::slotShowContextMenu(const QPoint &pos)
      {
          qDebug() << "Show context menu : " << pos;    QPoint posMenu = pos; // non-const QPoint
          QMenu contextMenu(tr("Context menu"), this);    QAction *action1 = contextMenu.addAction("Action1");
          QAction *action2 = contextMenu.addAction("Action2");    connect(action1, SIGNAL(triggered()),
                  this, SLOT(slotItemMenu1Clicked()));
          connect(action2, SIGNAL(triggered()),
                  this, SLOT(slotItemMenu2Clicked()));    connect(&contextMenu, SIGNAL(aboutToHide()),
                  this, SLOT(slotContextMenuClosed()));    contextMenu.exec(mapToGlobal(posMenu));
      }
      
      void MainWindow::slotItemMenu1Clicked()
      {
          qDebug() << "Menu action 1 triggered";
      }
      
      void MainWindow::slotItemMenu2Clicked()
      {
          qDebug() << "Menu action 2 triggered";
      
      }
      
      void MainWindow::slotContextMenuClosed()
      {
          qDebug() << "Close context menu";
      }
      
      
      
      // mainwindow.h
      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QDebug>
      #include <QMouseEvent>
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      public slots:
          void slotShowContextMenu(const QPoint &pos);
          void slotItemMenu1Clicked();
          void slotItemMenu2Clicked();
          void slotContextMenuClosed(void);
      
      protected :
          void mousePressEvent(QMouseEvent *event);
          void mouseReleaseEvent(QMouseEvent *event);private:
          Ui::MainWindow *ui;
      };
      
      #endif // MAINWINDOW_H
      
      
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vestbo Tor Arne Vestbø
            sebastienl Séb Lissarre
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes