What I need is a QMenu that displays a button, and when I press the button,
it triggers an action and goes away. I have managed all except the last
part: the QWidgetAction doesn't disappear (more specifically: the program blocks
execution on QMenu::exec(), no matter if QWidgetAction::trigger() is executed or not.)

What is the correct (!) way to let QWidgetAction behave like a simple
QAction in QMenu (i.e. to remove the widget after triggering the action and let QMenu::exec() return the QWidgetAction.)?
Take the the example below as a starting point:

Qt Code:
  1. class A : public QWidgetAction {
  2. public:
  3. A(QObject *parent = 0) : QWidgetAction(parent){
  4. QPushButton *b = new QPushButton("BUTTON");
  5. setDefaultWidget(b);
  6.  
  7. connect(b, SIGNAL(clicked()),
  8. this, SLOT(trigger())); //Docs suggest executing this
  9. connect(b, SIGNAL(clicked()),
  10. this, SIGNAL(triggered()));
  11. }
  12. };
To copy to clipboard, switch view to plain text mode 

PS Something similar was asked here, but is left unresolved. For the guy QMenu::exec() returns the QWidgetAction on second QWidgetAction::trigger() execution, but for the above code it does not, no matter how many signals are sent.

PPS Currently I have a workaround using
Qt Code:
  1. QKeyEvent *e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
  2. QCoreApplication::postEvent(this->parent(), e);
To copy to clipboard, switch view to plain text mode 
but that shouldn't be the way to go.