2

I want to remove (not all) menubar with python. I will put the code in startup.py so that when loading QGIS, automatically just only one menu that is 'Project' menu. I get the code from Finding the children name of menubar in QGIS Python.

@xunilk and @Joseph gave the answer. The code :

from PyQt4.QtGui import QToolBar, QDockWidget, QMenuBar
from qgis.utils import iface

for x in iface.mainWindow().findChildren(QMenuBar):
    print x.objectName()
for item in x.actions():
    print item
for i, item in enumerate(x.actions()):
    print i+1, 'name: ', item.icon().name()
for item in x.actions():
    if item.text().replace('&','') == 'Edit':
       item.setVisible(False)
    if item.text().replace('&','') == 'View':
       item.setVisible(False)
    if item.text().replace('&','') == 'Layer':
       item.setVisible(False)
    if item.text().replace('&','') == 'Settings':
       item.setVisible(False)
    if item.text().replace('&','') == 'Plugins':
       item.setVisible(False)
    if item.text().replace('&','') == 'Vector':
       item.setVisible(False)
    if item.text().replace('&','') == 'Raster':
       item.setVisible(False)
    if item.text().replace('&','') == 'Database':
       item.setVisible(False)
    if item.text().replace('&','') == 'Web':
       item.setVisible(False)
    if item.text().replace('&','') == 'Processing':
       item.setVisible(False)
    if item.text().replace('&','') == 'Help':
       item.setVisible(False)

All menus (except 'Project' menu) are successfully removed. Only three menus that not succeed to be removed. They are 'Database', 'Web', and 'Processing'. Why are these menus not removed, while I have written the code for them?

2
  • 1
    ok, it is work. I disable all plugin.
    – mega
    Mar 1, 2017 at 23:50
  • Glad it worked, will the post the comment as an answer for the convenience of others :)
    – Joseph
    Mar 3, 2017 at 11:12

1 Answer 1

1

If you have enabled plugins which fall under those menubars, they will remain even after running your code.

Therefore, to completely remove the required menubars, make sure all plugins for the desired menubar is disabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.