Can i change symbology style with a qml plugin

Hi,
I would like to know if someone knows how change symbology style for a layer with a .qml plugin?
For exemple, i have a points layer with a cluster symbology and another style without cluster symbology and i would like change this style via a qml plugin.

Thanks

@woupss , that’s not yet possible. It’s a relatively complex set of scenarios here (having to deal both with renderers and their associated symbol(s)). It’s something I’d love to brainstorm about with other plugin developers on how we could have something useful unlocked on that front.

I don’t have much experience with styling. Still, since you can configure multiple styling layers and enable/disable them based on expressions, you could store which styling layer to use for a given feature ID and determine the styling a feature should use based on the queried information.

A plugin can access that hidden layer to change its values based on in-app events.

As an example, since almost all attributes inside a styling layer can be set using expressions, instead of the “styling layer to use” you could store a color, and this way give each cluster a different color.

Never used this, so I don’t know how performant this would be, or if this would even work.
And I’m not sure I understood your endgoal correctly, but I still hope this idea is useful in some way!

1 Like

Hi Pascal,
It’s for my personnal uses, that i would like to know how do that, not for a public plugin but we never know…

I use it but from a layer but from a plugin it doesn’t work because features are not created.

Could you explain to me how, if you know, how show or hide a prĂ­vate layer

Is it possible with clustered layer too?

My end goal is to integrate it with my personnal filter plugin ( a project plugin really more complex and adapted for a specific project)

Sure, I’ll try to explain in more detail!

You can hide layers by marking them as private in your project settings:

They won’t be shown in QField, but plugins and expressions can still access them.

To still see them in QGIS, you have to adjust your legend filter to also show private layers

I don’t see why it wouldn’t. If you make your hidden data structure complex enough, you should be able to use it with everything you can query expressions for.

Let me break down my color example a bit more so it might be easier for you to adapt to your use case.
Let’s say we call our hidden layer could look like this:

id feature_id color_hex

Your expression for the color could then look up the color for the current feature and default to blue, while your plugin could allow you to select a color for all currently selected features and store it in the hidden layer. In theory, if you, e.g., select features 2 and 7 and set them to green using the plugin, both those features should then be green instead of blue, while all the other ones are still blue. Your hidden layer would then look something like this:

id feature_id color_hex
1 2 #008000
2 7 #008000

Since the project needs a certain structure with the hidden-layer approach, I don’t think it would be a good fit for a public app plugin anyway.

It’s a bit convoluted, but I still hope that helps! :grinning_face_with_smiling_eyes:

Edit: Data wise it should be similar to what we did with our Project Plugin for Feature Voting , that’s where I got the idea from when I read your question.

Thanks Pascal
Actually i made it works with map themes and the plugin to change layers styles.
But there is a limitation, i can’t show or hide a layer when a layer is in private mode
So actually i need to show my points layers and hide it when there is not plugin filter active and show layer when plugin filter is active

I see your subject and i think it a nice idea

1 Like