What does QWidget.addAction() do actually?
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.
Re: What does QWidget.addAction() do actually?
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.
Re: What does QWidget.addAction() do actually?
Quote:
Originally Posted by
Lykurg
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?
Re: What does QWidget.addAction() do actually?
Quote:
Originally Posted by
jezz
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.
Re: What does QWidget.addAction() do actually?
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).