[QGIS-Developer] Adding a panel to layer properties dialog from a python plugin

Denis Rouzaud denis.rouzaud at gmail.com
Thu Oct 18 03:32:42 PDT 2018


Hi again,

Sorry I pasted the wrong links...
This was for adding a page to global options.

Here it is for layers.
https://qgis.org/pyqgis/master/gui/other/QgisInterface.html#qgis.gui.QgisInterface.registerMapLayerConfigWidgetFactory

https://qgis.org/pyqgis/master/gui/Map/QgsMapLayerConfigWidgetFactory.html

There you have to implement supports layers. So it is very likely that it
will work for rasters but did not check.

Denis

On Thu, 18 Oct 2018, 03:37 Ricardo Filipe Soares Garcia da, <
ricardo.garcia.silva at gmail.com> wrote:

> Hi Denis, all
>
> I keep forgetting there are now also (totally cool) docs for the python
> API... I guess old habits die hard ;)
>
> From your tip I guess the problem I'm facing is likely related to my class
> inheriting from the wrong base ( as I'm not using QgsOptionsPageWidget).
>
> I'll try it out later and let you know ;)
>
> As for the raster layer properties dialog , is this indeed not implemented
> there?
>
> Best regards
>
>
> Denis Rouzaud <denis.rouzaud at gmail.com> escreveu no dia quinta,
> 18/10/2018 à(s) 01:49:
>
>> 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
>>
>>
>>
>
> --
> ___________________________ ___ __
> 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/20181018/6d977f3e/attachment-0001.html>


More information about the QGIS-Developer mailing list