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 :


But, for the child?

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


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:

  • Or disable them:

    for icon in iface.mapNavToolToolBar().actions(): 
        if icon.objectName() in icon_list:
  • Joseph, I have tried your sintax, but the toolbar is still there. It just can't be clicked. So, how to remove the toolbar? I change the code : icons.setEnabled(False) to become icons.setVisible(False). But nothing happen. I want to remove some of toolbar. – mega Feb 16 '17 at 23:37
  • @mega - Edited my post which allows you to hide (or disable) certain icons in a toolbar :) – Joseph Feb 17 '17 at 11:01
  • Joseph, it is work. Thanks. By the way, I try to show Layers Panel children name. I type : for icon in iface.Layers().actions(): print icon.objectName(). It is error. I want to hide layer panel children too. – mega Feb 20 '17 at 0:00
  • @mega - Most welcome, glad it worked! The Layers Panel is part of the QDockWidget so you will need to use: from PyQt4.QtGui import QDockWidget for x in iface.mainWindow().findChildren(QDockWidget): if x.objectName() == 'Layers': x.hide() – Joseph Feb 20 '17 at 10:21
  • I mean, how to show the children name of Layers Panel in python? The children name are 'Open the layer styling dock', 'Add group', 'Manage layer visibility', etc. Then, I will test to remove some of children of Layers Panel. I share the screenshot : 1drv.ms/f/s!Amfzr7zpdbRqjF-ZV7ZoTva_50zR – mega Feb 20 '17 at 23:44

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.