I am creating a dock widget for my plugin and i want my widget to be fixed to the Qgis window. How can i do that using python programming?


This question is perhaps better suited to StackOverflow, as it doesn't specifically relate to GIS (other than that the application you're using is QGIS).

To create a new dock widget and add it to the left panel:

dockwidget = QtGui.QDockWidget(iface.mainWindow())
iface.addDockWidget(Qt.LeftDockWidgetArea, dockwidget)

If the user moves it to a floating window you can then re-dock it using setFloating:


If you want to prevent the user from moving it to a floating window you need to set the "features" of the widget. In the example below, the widget is movable and closable, but not floatable:

dockwidget.setFeatures(QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable)
  • I have created DockWidget using QT designer and chosen the options as QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable. But when i am calling in my plugin it is not getting fixed to the table space? – user99 Jun 29 '15 at 9:44
  • Does calling setFloating not have any effect? – Snorfalorpagus Jun 29 '15 at 13:18
  • No I have selected/deselected Floating option in QT designer itself but it doesnot show any effect. – user99 Jun 30 '15 at 5:36

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.