PDA

View Full Version : What does QWidget.addAction() do actually?



jezz
16th September 2010, 14:26
Hi, I don't really understand what QWidget.addAction() does even after reading the documentation, I do the following:


connect(action_Close, SIGNAL(triggered()), this, SLOT(close()) );
buttonClose->addAction(action_Close);



I figure that the above code would cause clicking buttonClose to call close() and close the window. But nothing happen, what am I doing wrong?

The compiler output doesn't show any error about assigning the signal and slot. And close() is a SLOT in QWidget.

Lykurg
16th September 2010, 14:52
That's the wrong approach, you either use the QPushButtons clicked signal or use a action which can be triggered. addAction() adds an action to a widget and it is shown when the context menu of this widget is requested.

jezz
16th September 2010, 15:23
That's the wrong approach, you either use the QPushButtons clicked signal or use a action which can be triggered. addAction() adds an action to a widget and it is shown when the context menu of this widget is requested.

Thanks, but what do you mean by "action which can be triggered"? Aren't all QAction can be triggered?

Lykurg
16th September 2010, 15:28
Thanks, but what do you mean by "action which can be triggered"?Yeah, it is missunderstandable. I meant, that if you use addAction on the widget you can't trigger the added action directly. Other example: Add an action to a QToolButton, then you can trigger that action directly by clicking the button.

wysota
16th September 2010, 16:24
addAction() only associates a given action with a given widget, nothing more. Some widgets (like QToolBar) detect such associations and perform additional things then (i.e. QToolBar creates a tool button, initializes it with the action and adds it to its own layout).