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:
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?
-
If you direct the pointer to the edge of toolbar, it will give you the name. I give you screenshot the toolbar : 1drv.ms/f/s!Amfzr7zpdbRqjEBvvp8DkqD3F27mmega– mega2017年02月12日 23:43:19 +00:00Commented Feb 12, 2017 at 23:43
1 Answer 1
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:
- Menu Toolbar = QMenuBar
- Browser Panel = QDockWidget
- Label Toolbar = QToolBar
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)