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.

Eva Großmann
5311 gold badge3 silver badges16 bronze badges
asked Nov 22, 2017 at 14:37

1 Answer 1

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()
answered Nov 22, 2017 at 16:20
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.