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
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)
-
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?– user99Commented Jun 29, 2015 at 9:44
-
-
No I have selected/deselected Floating option in QT designer itself but it doesnot show any effect.– user99Commented Jun 30, 2015 at 5:36