[QGIS-Developer] How to restore dock widget plugin size after relaunch of QGIS?

Nyall Dawson nyall.dawson at gmail.com
Wed Nov 16 14:30:45 PST 2022


On Thu, 17 Nov 2022 at 02:22, Jean-Baptiste Peter via QGIS-Developer
<qgis-developer at lists.osgeo.org> wrote:
>
> Hi,
>
>
>
> I am working on a QGIS plugin which is based on QGIS plugin Builder dock widget template. The default behavior of this template is that the dock widget is not restored after closing and reopening QGIS. Here is the repo of my plugin:
>
> https://github.com/jbp35/layout_panel

Try calling .setObjectName() in the constructor of your dock widget
subclass. That's required for the standard QGIS dock arrangement
save/restore code to work correctly. (That's all that's needed -- you
don't need to manually do any calls to saveGeometry/restoreGeometry).

Also I suggest using the QgsDockWidget subclass as the base class for
your widget, as it has some extra niceness added on top of the
standard Qt QDockWidget class.

Nyall


>
>
>
> I managed to reopen the dock widget automatically when QGIS starts by calling the run() function from initGui() function. However, the dimensions of the widget is not saved and I am not able to figure out how to restore the width and height of the widget. I tried to use QDockWidget::restoreGeometry without success. Could someone please point me how to achieve this? Thanks!
>
>
>
> Best,
>
>
>
> --
>
> Jean-Baptiste PETER
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list