[Interest] Can't get menu with QWidgetAction to close after click! (Mac OS 10.6.8, Qt 4.8.3)

Jim Prouty jim at wavemetrics.com
Wed Oct 10 03:25:14 CEST 2012

On Oct 9, 2012, at 5:29 PM, Alex Malyushytskyy wrote:

> By the way try to call   QAction->trigger();
> in _onPushButton(bool b)
> If MAC implementation depends on this signal it definitely should
> solve the problem.
> By default QWidgetAction does not call it:
> "Note that it is up to the widget to activate the action, for example
> by reimplementing mouse event handlers and calling
> QAction::trigger()."

This does not close the menu, either. Again, on Macintosh (using Cocoa menus).

Though I'm not using the signal from the QWidgetAction in the test case, I amended the code to try this idea out.

I stashed the SpinBoxAction (derived from QWidgetAction) in the application's _wAction3 member variable and called trigger() on it in the _onPushButton() slot:

     // Widget Action 3
    SpinBoxAction * spinBoxAction = new SpinBoxAction(QLatin1String("Done"),menu);
    app._wAction3= spinBoxAction;
    menu->addAction( spinBoxAction );

    if( QWidget *widget= spinBoxAction->requestWidget(menu) ) {
        if( QPushButton *button = widget->findChild<QPushButton *>() ) {
            QObject::connect(button, SIGNAL(clicked(bool)), &app, SLOT(_onPushButton(bool)));


  void SpinApplication::_onPushButton(bool b)
         _wAction3->trigger();  // doesn't help close the menu, but may have been necessary to propogate the trigger to receivers of the action.
     if(_menu) {
        _menu->hide();             // doesn't help
        bool closed= _menu->close(); // doesn't work
         qDebug() << "Closed:" << closed;


Jim "How does it work?" Prouty

Voice: (503) 620-3001, FAX: (503) 620-6754
Makers of IGOR Pro, scientific data analysis and graphing for Mac and PC

More information about the Interest mailing list