3

Some of the QGIS tools can be selected/activated via PyQGIS using the iface object (see QgisInterface). For example:

iface.actionIdentify().trigger() # Activates the Identify tool

However, the Text Annotation tool (and also HTML, SVG, and Form annotation tools) are not available in iface.

How can I select/activate the Text Annotation tool from my QGIS python plugin?

1
  • 1
    Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq.
    – underdark
    Commented Dec 8, 2016 at 16:42

1 Answer 1

2

Since there's no direct method to select the QGIS Text Annotation tool from the iface object, you can do it in this way:

For QGIS 2.x

from PyQt4.QtGui import QAction
iface.mainWindow().findChild( QAction, 'mActionTextAnnotation' ).trigger()

Updated for QGIS 3.x

from qgis.PyQt.QtWidgets import QAction

iface.mainWindow().findChild( QAction, 'mActionHtmlAnnotation' ).trigger()

You can use the others related actions e.g mActionFormAnnotation, mActionHtmlAnnotation, mActionSvgAnnotation instead of mActionTextAnnotation

1
  • 1
    It worked!, that worked perfectly.
    – Mai
    Commented Dec 25, 2016 at 9:13

Your Answer

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

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