4

I'm trying to "click" a button in the "Raster Toolbar" in QGIS 2.14 via PyQGIS, but don't know how to do this correctly. I can access the toolbar itself with

rtools = qgis.utils.iface.rasterToolBar()

But after that, I have no clue how to get the correct button. I think I can aceess the single buttons like this:

buttons = [c for c in rtools.children() if type(c) is QToolButton]

but I only know the hover text (e.g. "Local Histogram Stretch") and not the name or ID or whatever can be used here as an identifier. All fields which I thougt might contain something useful have been empty strings.

Does anyone know the proper way of "clicking" a button via code?


Just found the actual action I was searching, so I could use Trigger plugin button using PyQGIS? to get that specific button to be "clicked", but what if I don't know the QAction?

There must be a way of identifying the button through one of its properties.

6

You can get the actions for a toolbutton tb using:

actions = tb.actions()

This returns a list. You can then examine the text associated with each:

for action in actions:
    print action.text()

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.