[QGIS-Developer] Adding a panel to layer properties dialog from a python plugin
Denis Rouzaud
denis.rouzaud at gmail.com
Wed Oct 17 17:48:51 PDT 2018
Hi Ricardo,
For python, looking at the python API is always a good start ;)
https://qgis.org/pyqgis/master/gui/other/QgisInterface.html#qgis.gui.QgisInterface.registerOptionsWidgetFactory
This means you must give a QgsOptionsWidgetFactory
https://qgis.org/pyqgis/master/gui/Options/QgsOptionsWidgetFactory.html
Here the docs could be clearer but this is the class you have to inherit.
You need to implement title, icon and createWidget. In the latter, you'll
be able to load your UI and return the widget to be displayed. The widget
you return must inherit QgsOptionsPageWidget.
I hope this helps!
Denis
On Wed, 17 Oct 2018, 18:24 Ricardo Filipe Soares Garcia da, <
ricardo.garcia.silva at gmail.com> wrote:
> Hi all
>
> The API docs for QgisInterface[1] mention the existence of a
> `registerMapLayerConfigWidgetFactory()` method which says in its
> documentation:
>
> > Register a new tab in the vector layer properties dialog.
>
> I've been trying to test this out and see if I can add a new panel to a
> layer's properties dialog via a Python plugin. So far I've had no luck.
> Couldn't find any other docs/samples online showing how to do this. Perhaps
> someone can help me out?
>
> Here is what I have:
>
> - made a custom .ui file in Qt designer with a simple QWidget that only
> has a QLabel inside
> - implemented a class inheriting from both
> `qgis.gui.QgsMapLayerConfigWidget` and my ui file (after it is loaded with
> uic.loadUiType)
> - implemented a class inheriting from
> `qgis.gui.QgsMapLayerConfigWidgetFactory`. This class implements all of the
> methods declared as *virtual* in the cpp API, including the
> `createWidget()`, which returns a new instance of my custom
> maplayerconfigwidget class
> - in my plugin's `initGui()` method I'm calling
> `iface.registerMapLayerConfigWidgetFactory()` and pass along my custom
> factory
>
> I guess this should be enough to have a minimum working prototype.
> However, this is what happens:
>
> - When I load up a vector layer and then open it's properties dialog, QGIS
> just crashes with a core dumped message.
> - When I load up a raster layer and then open it's properties dialog,
> nothing happens. I suspect this functionality is probably not even
> available for raster layers. Is this true?
>
> Can someone provide some pointers or some existing reference on how this
> would work? Thanks in advance
>
> [1] -
> https://qgis.org/api/classQgisInterface.html#a2c64949239a7717d181e34d6f2c47851
>
> --
> ___________________________ ___ __
> Ricardo Garcia Silva
> _______________________________________________
> 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
--
Denis Rouzaud
denis at opengis.ch <denis at opengis.ch>
+41 76 370 21 22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20181017/954eed4a/attachment.html>
More information about the QGIS-Developer
mailing list