Question

I was wondering if there is a way to convert my QT (version 4.50) menu and all its submenus into a text document in something similar to the following format:

  • Menu 1
    • Sub Menu 2
  • Menu 2
    • sub menu 3
    • sub menu 4
      • sub menu 1
Was it helpful?

Solution

You might want to look at QObject::findChildren, and use it like this:

submenus = mainwindow.menuBar().findChildren(QAction)

Depending on how you construct your menus you might have to use QMenu as a parameter aswell. Also depending on your usage some sub menus could have no parent (depending on how you constructed them or added them to the parent menu) and then findChildren won't find them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top