Find all actions in .ui form
-
Hi.
How to dynamically find all .ui form actions?
For example:
@QList<QAction *> allactions = parentWidget()->findChildren<QAction *>();
or
QAction *action = menuBar()->findChild<QAction *>("action_name");@For all Widgets it works, but not for QActions. menuBar(), menuWidget(), parent(), parentWidget() can't find actions at all.
-
QObject::findChildren() returns all objects with a given type and optional a given object name whose parent is directly or indirectly the given QObject.
The parent for actions added using the UI designer is always the top-level widget, for example MainWindow, and <code>this->findChildren<QAction*>()</code> or simply <code>findChildren<QAction*></code> should return a list of all actions.
If you add a QAction to a menu bar the menu bar does not become the parent of the action. You will have to use QMenu::actions() to retrieve a list of actions.
-
Thanks.
Now all works great.