Feature request #14011

Access QGIS measurement (and all QWidgetAction) widget with a deterministic approach

Added by Thomas Gratier almost 9 years ago. Updated over 7 years ago.

Status:Open
Priority:Normal
Assignee:-
Category:Map Tools
Pull Request or Patch supplied:No Resolution:
Easy fix?:No Copied to github as #:22024

Description

To access the measurement widget in the toolbar that contains "Measure Line", "Measure Area" and "Measure Angle", I have to do the following:

    iface.attributesToolBar().actions()[8]


The problem: it's not deterministic if I choose to add or remove buttons in the "Attributes Toolbar"

If I do below code, It's again not deterministic because I depend from the translated string


    from PyQt4.QtGui import QWidgetAction

    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.defaultWidget().actions()[0].text() in ["Measure Line", "Measure Area", "Measure Angle"]:
                print action.defaultWidget().actions()[0].text()

So, I would expect something like

    from PyQt4.QtGui import QWidgetAction

    for action in iface.attributesToolBar().actions():
        if isinstance(action, QWidgetAction):
            if action.data() == "qwidget_measure":
                print "It the measurement QWidget" 

I don't know if I missed an alternate better way.

If there are not better way, the proposed changed would make action.data() contains an id instead of None at the moment.

I also don't know if it's the best solution too (not enough year of experience with Qt/PyQt)

History

#1 Updated by Giovanni Manghi over 7 years ago

  • Easy fix? set to No

#2 Updated by Regis Haubourg over 7 years ago

  • Category changed from Actions to Map Tools
  • Description updated (diff)

Also available in: Atom PDF