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?
Answer
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.
No comments:
Post a Comment