[Qt-interest] QWidgetAction stays visible after triggered() signal and trigger() slot.

Davor J. DavorJ at live.com
Thu Mar 4 10:36:39 CET 2010


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 menu doesn't disappear (more specifically: the program blocks 
execution on QMenu::exec(), no matter if 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.)? 
Take the the example below as a starting point:

class A : public QWidgetAction {
public:
    A(QObject *parent = 0) : QWidgetAction(parent){
        QPushButton *b = new QPushButton("BUTTON");
        setDefaultWidget(b);

        connect(b, SIGNAL(clicked()),
                this, SLOT(trigger())); //Docs suggest executing this
        connect(b, SIGNAL(clicked()),
                this, SIGNAL(triggered()));
    }
}; 





More information about the Qt-interest-old mailing list