Feature request #14011

Updated by Regis Haubourg over 7 years ago

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



<pre>

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



</pre>

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



<pre>



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()

</pre>



So, I would expect something like



<pre>

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"

</pre>



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)



Back