[QGIS-Developer] Custom python expression question

Matthias Kuhn 🌍 matthias at opengis.ch
Fri May 5 05:08:24 PDT 2017

Actually, there would also be the "context" which gives access to the
@layer variable (a QgsVectorLayer object) and other additional things.

It's just slightly more complex to set up because it's not proxied to
the @qgsfunction.

One will need to subclass QgsExpression.Function as done here:


And then register it manually.

I think we should also send this to the @qgsfunction in QGIS 3.


On 05/05/2017 12:42 PM, Nathan Woodrow wrote:
> Hey Andreas,
> Parent means the parent expression itself.  So in a function, you can
> know what the whole expression is e.g it points to the instance of. 
> You can't really know what the layer because expressions are not always
> layer bound and QgsFeatures don't hold a reference to the layer they are
> from.  Best you can do at the moment I think is to pass the layer name
> or id into the custom expressions.
> - Nathan
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

More information about the QGIS-Developer mailing list