1

I've added a custom toolbar with some buttons to my QGIS 2 plugin. I'm wondering how to get the button toggled (pushed in-looking effect) using Python. I've gotten this to work for existing buttons like so:

iface.actionAddFeature().trigger()

I can't seem to figure out how to apply it to my own actions and buttons.

1

When you create action for button add:

self.myaction.Checkable(True)

In action callback, when you set your tool as active, toggle button on:

self.iface.mapCanvas().setMapTool(self.myTool)
self.myaction.setChecked(True)

Add tool deactivation callback, which toggle button off:

def deactivate(self):
    self.myaction.setChecked(False)

And connect it somewhere in init code:

self.iface.mapCanvas().mapToolSet.connect(self.deactivate)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.