Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Find all actions in .ui form
Qt 6.11 is out! See what's new in the release blog

Find all actions in .ui form

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    betmens
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        betmens
        wrote on last edited by
        #3

        Thanks.
        Now all works great.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved