Saturday, 17 December 2016

pyqgis - Name of children of toolbar in QGIS python and how to disable?


There are name of toolbar you can see in : Finding name of QGIS toolbar in Python?


But, I want to know the name of children of toolbar. For example, the children of mapNavToolBar are touch zoom and pan; pan map; pan map to selection; zoom in; zoom out; etc. Then if we know the name, how to disable in python?


For example to disable menuBar you can type the script :


iface.mainWindow().menuBar().setVisible(False)

But, for the child?



I want to show not all mapNavToolBar, Layers Panel, and menuBar.



Answer



First, we can find all object names of the icons in the mapNavToolBar using:


for icon in iface.mapNavToolToolBar().actions(): 
print icon.objectName()

Decide which ones you want to modify then add them to a list:


icon_list = ['mActionDraw', 'mActionPan', 'mActionZoomIn']

Now, you can either:





  • Hide them:


    for icon in iface.mapNavToolToolBar().actions(): 
    if icon.objectName() in icon_list:
    icon.setVisible(False)







  • Or disable them:


    for icon in iface.mapNavToolToolBar().actions(): 
    if icon.objectName() in icon_list:
    icon.setEnabled(False)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...