You can access QGIS toolbar buttons (actions) by using the
iface object (docs here). From those actions you can create a
QActionGroup and add your custom action making all actions mutually exclusive.
The following code snippet shows you how to do it, step by step. I've put the code snippet in the
initGui(self) method of my test plugin.
# Make sure your action can be toggled
self.action.setCheckable( True )
# Build an action list from QGIS navigation toolbar
actionList = self.iface.mapNavToolToolBar().actions()
# Add actions from QGIS attributes toolbar (handling QWidgetActions)
tmpActionList = self.iface.attributesToolBar().actions()
for action in tmpActionList:
if isinstance(action, QWidgetAction):
actionList.extend( action.defaultWidget().actions() )
actionList.append( action )
# ... add other toolbars' action lists...
# Build a group with actions from actionList and add your own action
group = QActionGroup( self.iface.mainWindow() )
for action in actionList:
group.addAction( action )
group.addAction( self.action )
You can get a demo plugin showing this behavior from here. In the README file you have installation and configuration instructions.
After installing the demo plugin, you can notice your plugin button deactivates QGIS buttons and the other way around.
Note: I've only included actions from the Navigation and Attributes QGIS toolbars. You might need to add other QGIS toolbar actions as well. All QGIS toolbars you can get are exposed in the QgisInterface.