2

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
    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 Dec 8 '16 at 16:42
1

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

from PyQt4.QtGui import QAction
iface.mainWindow().findChild( QAction, 'mActionTextAnnotation' ).trigger()
  • 1
    It worked!, that worked perfectly. – MikaEG Dec 25 '16 at 9:13

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.