[GIS] How to remove group filter applied via Python-console (setSubsetString) of QGIS

group-layerpythonqgisqgis-plugins

I need to quickly apply (and then change/remove) the same filter for about 100 layers in my QGIS project (all put together in one group). Since there is no implemented solution right now (a feature request already exists for this issue), I searched the internet and found a good working workaround using the python-console and the function setSubsetSring. The syntax (in my case) is as follows:

layers = iface.mapCanvas().layers()
for layer in layers:
layer.setSubsetString('"Art" = \'Ki\'')

I can now apply the filter to any visible layers at once, and also change it by repeating the code and changing the value '\Ki' to something else like '\Fl' or anything else.
Waht I now want to do is to remove the applied filter, so all features will be visible again.
Since I'm absolutely new to Python, I just cant't figure out the right syntax for this job. Already tried things like

layer.setSubsetString('"Art" != \'xyz\'')

and something else, but I always get something like

File "<input>", line 2 layer.setSubsetString('"Art" != \'xyz\") IndentationError: expected an indented block

Best Answer

layers = iface.mapCanvas().layers()
for layer in layers:
   layer.setSubsetString('"Art" = \'Ki\'')

to clear:

layers = iface.mapCanvas().layers()
for layer in layers:
   layer.setSubsetString('')
Related Question