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

Suggestion to make QMenu::exec() return a QAction pointer if the keyboard shortcut is used

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.2.3
    • Core: Event loop
    • None

    Description

      It seems inconsistent that QMenu::exec() does not return a pointer to the QAction when the action is triggered with the shortcut.

      popup.exec() will return:

      • 0 if the Escape key is used or clicking besides the menu.
      • The QAction* is returned if selecting the menu entry by clicking it, the action is also triggered.
      • The QAction* is returned if selecting the menu entry and hitting return, the action is also triggered.
      • 0 if the keyboard shortcut 'n' is used, the action is also triggered. It would be nice if the QAction * was returned instead of 0.

      Reproducible with:

      #include <QtGui>
      #include <QDebug>

      class CustomWidget : public QPushButton
      { Q_OBJECT
      public:
      CustomWidget(QWidget* parent=0) : QPushButton(parent)

      { connect(this,SIGNAL(clicked()), this, SLOT(aSlot())); }

      public slots:
      void aSlot()
      {
      qDebug() << "aSlot invoked";
      QAction * actAdd = new QAction(QPixmap("/1.png"), tr("d&new"), this);
      connect(actAdd, SIGNAL(triggered()), this, SLOT(slot2()));
      QMenu popup;
      popup.addAction(actAdd);
      QAction *choice = popup.exec(QCursor::pos());
      if (choice == 0)

      { qDebug() << "0"; }

      }

      void slot2()

      { qDebug() << "slot2"; }

      };

      #include "main.moc"

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);
      CustomWidget wid;
      wid.show();
      return app.exec();
      }

      Attachments

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

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes