Details
-
Suggestion
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.2.3
-
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)
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)
}
void slot2()
{ qDebug() << "slot2"; }};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CustomWidget wid;
wid.show();
return app.exec();
}