<div dir="ltr"><div dir="ltr"><div>Hi Richard</div><div><br></div><div>You can add widgets to a specific layer if you know the widget provider's id. It is simply a matter of setting up the relevant custom properties.</div><div><br></div><div>Take a look at the code in the PR you linked, more specifically here:</div><div><br></div><div><a href="https://github.com/qgis/QGIS/pull/3170/files#diff-0c8d41d794f1b84a1291aa29bb39392aR114">https://github.com/qgis/QGIS/pull/3170/files#diff-0c8d41d794f1b84a1291aa29bb39392aR114</a></div><div><br></div><div><br></div><div>For example, the standard widget that provides a transparency slider has an id of "transparency". Lets imagine I select the current layer in the canvas and then want to make this widgets appear in its legend:</div><div><br></div><div>```python</div><div>layer = iface.activeLayer()</div><div>layer.setCustomProperty("embeddedWidgets/count", 1)</div><div>layer.setCustomProperty("embeddedWidgets/0/id", "transparency")</div><div>iface.layerTreeView().refreshLayerSymbology(<a href="http://layer.id">layer.id</a>())<br></div><div>```<br></div><div><br></div><div>This code assumes that the layer doesn't currently have any embedded widgets.</div><div><br></div><div><br></div><div>P.S. - Now that I've tried it, it seems that the transparency slider works differently for raster and vector layers.<br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Richard Duivenvoorde <<a href="mailto:rdmailings@duif.net">rdmailings@duif.net</a>> escreveu no dia quarta, 13/02/2019 à(s) 11:38:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Devs,<br>
<br>
Thinking about creating a small plugin which would add a 'Layer tree<br>
embedded widget' to a layer in the legend, I hit:<br>
<br>
<a href="https://github.com/qgis/QGIS/pull/3170" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/pull/3170</a><br>
<br>
with a nice example on how to create such a widget (with 2 minor tweaks<br>
see below).<br>
<br>
But my question is if it is possible (in the python plugin) to attach<br>
such widget to a specific layer? Now it is working but you can only<br>
activate it via the layerproperties dialog.<br>
<br>
I could not find a example or hint for it.<br>
<br>
Any pointers appreciated.<br>
<br>
Regards,<br>
<br>
Richard Duivenvoorde<br>
<br>
PS<br>
<br>
To make Martins example <a href="https://github.com/qgis/QGIS/pull/3170" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/pull/3170</a>) work in<br>
QGIS3:<br>
<br>
from PyQt4.QtGui import QComboBox<br>
becomes<br>
from qgis.PyQt.QtWidgets import QComboBox<br>
<br>
QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)<br>
becomes<br>
QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(provider)<br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">___________________________ ___ __<br>Ricardo Garcia Silva</div>