Reputation: 7889
Using Python and PyQt4, given a GUI with any number of QToolBar objects and each toolbar contains any number of QAction objects.
I can iterate the ui with the following code and find the toolbars:
for name, obj in inspect.getmembers(ui):
if isinstance(obj, QToolBar):
print "toolbar =",name
How can I iterate each toolbar object and find the QAction objects. I will then read the QActions to determine which are "checked". I am not using QActionGroups.
Upvotes: 1
Views: 2803
Reputation: 120608
If the toolbars were created in Qt Designer, they will become children of the main window (or whatever the top-level widget is).
So you can simply do:
for toolbar in mainwindow.findChildren(QToolBar):
print('toolbar: %s' % toolbar.objectName())
for action in toolbar.actions():
if not action.isSeparator():
print(' action: %s (%s)' % (action.text(), action.isChecked()))
Upvotes: 5