Hello, I am wondering if there is a way in PyQGIS to automate the process of selecting/deselecting the check marks for each categorized symbol in the included picture. I am writing a plugin and would like to be able to have the option of viewing one of the symbols at a time instead of seeing all of them at once. Thanks
This code snippet should do the work. The key is to use
updateCategoryRenderState(), which should be
True for checked values, and
False for unchecked ones.
layer = iface.activeLayer() renderer = layer.renderer() value = "100001" for i, cat in enumerate(renderer.categories()): renderer.updateCategoryRenderState(i, cat.value() == value) layer.setRenderer(renderer) iface.layerTreeView().refreshLayerSymbology(layer.id()) layer.triggerRepaint()