[Qgis-developer] QgsLayerTreeViewMenuProvider and default values

Martin Dobias wonder.sk at gmail.com
Mon Nov 21 07:40:57 PST 2016


On Mon, Nov 21, 2016 at 6:09 PM, Richard Duivenvoorde <richard at duif.net> wrote:
> On 2016-11-21 03:02, Martin Dobias wrote:
>
> Ah, thanks Martin for your anwers.
>
>>> Q3: looking at the possibility to add a 'Transparency slider' in the
>>> layertree (see layer props bottom item): how difficult is it to add a
>>> 'refresh data' button (with custom refresh data code) in the layer tree
>>
>>
>> See the original pull request for some example code:
>>
>> https://github.com/qgis/QGIS/pull/3170
>
>
> I tried this, and indeed can create such a widget (QToolButton or
> QPushBtuuon) with a handle to a layer to do things with it.
> But I can only add it to a layer in the legend via the properties dialog?

Here is how to configure an embedded widget without properties dialog:

my_layer.setCustomProperty("embeddedWidgets/count", 1)
my_layer.setCustomProperty("embeddedWidgets/0/id", "transparency")

Finally one needs to call refreshLayerLegend(), e.g.:

view = iface.layerTreeView()
view.model().refreshLayerLegend(view.currentNode())

The methods from QgsLegendInterface only affect the actions in context
menu for the layer tree, they are not related to embedded widgets
functionality.

Cheers
Martin


More information about the Qgis-developer mailing list