1

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?

1 Answer 1

4

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:

dockwidget.setFloating(False)

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)
3
  • 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
    Commented Jun 29, 2015 at 9:44
  • Does calling setFloating not have any effect? Commented Jun 29, 2015 at 13:18
  • No I have selected/deselected Floating option in QT designer itself but it doesnot show any effect.
    – user99
    Commented Jun 30, 2015 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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