Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'm working on a QGIS-plugin and want to move the default LayerPanel/Dockwidget to somewhere else programmatically. More specific: i want to move it into a tab of my tabwidget. Is this possible? How can i get access to that specic dockwidget out of python?

share|improve this question
up vote 3 down vote accepted

qgis.utils.iface.mainWindow() has findChild and findChildren methods.

Unfortunately the QDockWidgets that display a title of "Layers" and "Layer Order" both have an objectName of "Legend".

This code will gain access to the right widget:

from PyQt4.QtGui import *

layersDockWidget = None
legendDockWidgets = qgis.utils.iface.mainWindow().findChildren(QDockWidget, "Legend")
for dockWidget in legendDockWidgets:
  if dockWidget.windowTitle() == "Layers":
    layersDockWidget = dockWidget

It can then be placed by calling addWidget on any QLayout.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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