[QGIS-Developer] set data defined override expression with python?

Nyall Dawson nyall.dawson at gmail.com
Tue Aug 21 15:10:26 PDT 2018


On Wed, 22 Aug 2018 at 01:41, Raymond Nijssen <r.nijssen at terglobo.nl> wrote:
>
> Hi devs!
>
> I'd like my python plugin to set an expression for overriding a property
> and I have no clue how to do so. I expect there must be some generic way
> to set expressions.
>
> Specifically, I want to set the expression for the "Image source" of a
> QgsLayoutItemPicture to:
>
> '/path/to/pictures/' || attribute(@atlas_feature, 'ID') || '.svg'
>

Try

    property = QgsProperty.fromExpression( "'/path/to/pictures/' ||
attribute(@atlas_feature, 'ID') || '.svg'")
    item.dataDefinedProperties().setProperty(QgsLayoutObject.PictureSource,
property)

Nyall


More information about the QGIS-Developer mailing list