PushButton Based On Action: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(No difference)

Revision as of 16:19, 14 January 2015

Creating a QPushButton component configured by a QAction

QPushButton does not allow itself to be configured by a QAction. In the case when you need to share a QAction among different components like menus, buttons, and so on, you can simply extend the QPushButton class with code similar to the following:

The idea is to extend QPushButton and to provide a setAction method that will immediately configure the button itself with the action data. After that, the button will connect to the action, so that when the button is clicked the action is triggered and vice-versa: when the action is changed the button is re-configured.

The following is the implementation:

Categories: