In QGIS, with right-click somewhere in the toolbar area panels can be toggled on/off like shown in the screenshot below (the GPS Information Panel for instance).

enter image description here

I need to do this programmatically, so how to toggle on/off panels from PyQGIS? I found that the QgsInterface class has some addDockWidget and removeDockWidget method, but I really couldn't figure out if this is the right way to achieve this ...


Those panels are QDockWidgets, we can search for their objectNames and if it matches, set their visibility to False (i.e. hide them).

So for the GPS Information Panel, you could use:

from PyQt4.QtGui import QDockWidget
for x in iface.mainWindow().findChildren(QDockWidget):
    #print x.objectName()
    if x.objectName() == 'GPSInformation':

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.