During my work on the Fastener Workbench, I came into a need for a toggle button (or a check box). This button holds a state upon which some calculation is done when generating new fasteners.
However I did not find any support for such a button, nor did I find any example that do that.
To overcome this problem I used a small hack - every time the button is activated, I search the entire raw gui for this button, and then use setIcon() to switch the icon to another one giving me an effective toggle button: Here is the gui search code:
Code: Select all
def FSGetToolbarItem(toolbar_name, command_name):
mw = QtGui.qApp.activeWindow()
tb = None
for c in mw.children():
if isinstance(c, QtGui.QToolBar) and c.windowTitle() == toolbar_name:
tb = c
break
if tb == None:
return None
for c in tb.children():
if isinstance(c, QtGui.QToolButton) and c.text() == command_name:
return c
return None
Is there any standard way to add a toggle button to the workbench toolbar? or at least a way to access the command object itself and change the icon there?
Thanks!
shai