PyQGIS – Finding Name of QGIS Toolbar in Python

pyqgistoolbar

I want to run python script. I don't know the name of toolbar in python script language : menu toolbar, browser panel toolbar, and label toolbar.
The screenshots of the toolbars for which I don't know the python names of are:

enter image description here

enter image description here

enter image description here

To test the name of toolbar is true, I try to type in python script like this :

iface.menuToolBar().setVisible(False)

iface.browserpanelToolBar().setVisible(False)

iface.labelToolBar().setVisible(False)

But, the toolbar is still be visible. So the name of these toolbar is false. So, what the name of these toolbar?

Best Answer

Based on the answer and comments on this post: Tool Bar visibility in PyQGIS, we can determine the name of these objects and set their visibility to False. If you go to the menubar and select Settings > Customization, you can see the types of objects used. In your case:

So, we can find all the names of objects which fall under each of those object types by using:

from PyQt4.QtGui import QToolBar, QDockWidget, QMenuBar

# Get list of all ToolBars
for x in iface.mainWindow().findChildren(QToolBar): 
    print x.objectName()

# Get list of all Dockwidgets
for x in iface.mainWindow().findChildren(QDockWidget): 
    print x.objectName()

# Get name of MenuBar
for x in iface.mainWindow().findChildren(QMenuBar): 
    print x.objectName()

Once we have determined the names of the objects you are interested in, we can hide them:

  • Menu Toolbar: iface.mainWindow().menuBar().setVisible(False)
  • Browser Panel: iface.mainWindow().findChild(QDockWidget,'Browser').setVisible(False)
  • Label Toolbar: iface.mainWindow().findChild(QToolBar,'mLabelToolBar').setVisible(False)
Related Question