[QGIS-Developer] Access to shapeDigitizeToolBar menu's text

Jacky Volpes jacky.volpes at oslandia.com
Tue Feb 27 02:28:35 PST 2024


Hi Luke,

As you can see on the printed text, objects are QWigetAction, not QAction.
This is because you get each category of the tool bar, where then each 
one contains one or more digitizing QActions.


Here is a snippet that can help you explore the tool bar:


sdtb = iface.shapeDigitizeToolBar()
for i, action_widget_item in enumerate(sdtb.actions()):
     print(f"{i}: {action_widget_item.defaultWidget().text()}")
     for j, action_item in 
enumerate(action_widget_item.defaultWidget().menu().actions()):
         print (f"\t{j}: {action_item.data()}")  # id like
         print (f"\t\ttranslated text: {action_item.text()}")


Regards,

Jacky Volpes

Ingénieur SIG - Oslandia


Le 27/02/2024 à 04:10, Catania, Luke A ERDC-RDE-GRL-VA CIV via 
QGIS-Developer a écrit :
>
> Trying to get access to the button menus in shapeDigitizeToolBar.
>
> from qgis.utils import iface
>
> from PyQt5.QtWidgets import QWidgetAction
>
> sdtb = iface.shapeDigitizeToolBar()
>
> i=0
>
> for action_item in sdtb.actions():
>
>     i=i+1
>
>     print (f"{i}: {action_item}")
>
> This prints:
>
> 1: <PyQt5.QtWidgets.QWidgetAction object at 0x00000242801E98B0>
>
> 2: <PyQt5.QtWidgets.QWidgetAction object at 0x00000242F9E43F70>
>
> 3: <PyQt5.QtWidgets.QWidgetAction object at 0x00000242F9E590D0>
>
> 4: <PyQt5.QtWidgets.QWidgetAction object at 0x00000242F9E9E1F0>
>
> 5: <PyQt5.QtWidgets.QWidgetAction object at 0x00000242F9E274C0>
>
> I want to access each button and the menus of the button so I can 
> disable certain tools.  I need to get the text associated with the 
> tools so I can key on that.
>
> I can’t figure out how to get to them from QWidgetAction. I called all 
> the methods on QAction that returns a string: data, iconText, 
> statusTip, whatsThis and they all return empty strings.  So how are 
> these menus labeled.
>
> Thanks,
>
> Luke
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240227/6863c229/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: K7OHeEXDZ8qqx2H0.png
Type: image/png
Size: 22696 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240227/6863c229/attachment-0001.png>


More information about the QGIS-Developer mailing list