2

I am using the answer to Adding custom panel to QGIS to add a custom panel to my existing custom QGIS plug-in. So far, the plug-in only uses modal dialogues. I try to show the widget from the callback of a toolbar menu option:

file_widget = QgsFileWidget()
file_widget.setObjectName('filewidget_example')

container = QDockWidget('A file widget in a dockable container')
container.setWidget(file_widget)
container.setVisible(True)
self.iface.addDockWidget(Qt.RightDockWidgetArea, container)

On execution, the right-hand side of the map view slides to the left to make room for the panel, but nothing is shown and after about half a second, the view slides back. There is nothing in the logs. I can show the widget, so it is being created properly. The interface self.iface is being used a lot elsewhere in the plug-in, so I know this is valid.

I have tried moving the code so that it is executed at the end of the GUI initialisation, but nothing happens at all.

Any suggestions as to why this is not appearing properly and what I need to do?

1 Answer 1

3

This short snippet is working for me (QGIS 3.34):

from qgis.utils import iface 

dock_widget = QDockWidget("DockWidgetTest", iface.mainWindow())
label = QLabel('Test')
dock_widget.setWidget(label)
iface.mainWindow().addDockWidget(Qt.RightDockWidgetArea, dock_widget)

Note, that i specify the iface.mainWindow() as parent of the DockWidget and i use the addDockWidget method of QMainWindow (iface.mainWindow())

0

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.