I use QGIS and want to place an option that when pressed, I perform a filtering without the need to enter commands.

I am currently using the program to carry out an electricity project, where a series of high and low voltage electric poles and networks is loaded on a map, but when I finish loading these poles electric and networks layer I must correct the mistakes made in the tracing of networks or filling of spreadsheets, as we are several operators, at the end of the afternoon you must use the dialog expression to filter by operator the mistakes you make and I must place the command again and again, so I would like to add a button or option that allows me to select an already established filter.

How could this be done?

  • Can't you use the filter tool from the layers list? It's only 4-5 clicks to do exactly what you want. You need to change the operator each time you filter anyway, no?
    – Gabriel
    Commented Feb 7, 2020 at 14:17

1 Answer 1


One option would be to create a python action for each layer filter you want to set. The action can call the setSubsetString()method on the layer setting the attribute expression. See this q/a for a basic example using setSubsetString():

Subsetting a shapefile and saving it using PyQgis

See link below for how to create a python action.

Creating Custom Python Actions

To run the actions use the identify feature tool and right click over any of the layer features in the map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.