[Qgis-user] Expression to read field value from composer layout?

Patrick Dunford enzedrailmaps at gmail.com
Wed Aug 4 17:28:26 PDT 2021


Thanks for that. I also found a tutorial by Nathan Woodrow which 
explains how to do custom functions.

https://woostuff.wordpress.com/2015/05/21/accessing-composer-item-properties-via-custom-expressions-in-qgis/

On 5/08/21 12:51 am, Stefan Giese (WhereGroup) wrote:
>
> here is a function which does the job. It's a bit more generic, you 
> have to pass the layoutname and the itemID to get the text:
>
> /from qgis.core import *//
> //from qgis.gui import *//
> //
> //@qgsfunction(args='auto', group='Custom')//
> //def get_layout_textitem(layoutTitle, itemId, feature, parent)://
> //    """//
> //    Gets the text from a labelitem in the layout with the name 
> layoutTitle.//
> //    <h2>Example usage:</h2>//
> //    <ul>//
> //      <li>get_layout_textitem('Layout 1', 'text1') -> 'lorem 
> ipsum</li>//
> //    </ul>//
> //    """//
> //
> //    project = QgsProject.instance()//
> //    projectLayoutManager = project.layoutManager()//
> //    layout = projectLayoutManager.layoutByName(layoutTitle)//
> //
> //    fileNameLabel = layout.itemById(itemId)//
> //    fileNameText = fileNameLabel.text() //
> //    return fileNameText/
>
> //
>
> Am 04.08.2021 um 14:06 schrieb Patrick Dunford:
>> layoutTitle = "Landscape 16:9 Header Nav Copyright Filename 2021"
>>
>> project = QgsProject.instance()
>> projectLayoutManager = project.layoutManager()
>> layout = projectLayoutManager.layoutByName(layoutTitle)
>>
>> fileNameLabel = layout.itemById('Filename')
>> fileNameText = fileNameLabel.text() 
> -- 
> Mit freundlichen Grüßen
> Stefan Giese
> Projektleiter/Consultant
> ************************************************************
> Aufbau von Geodateninfrastrukturen mit Open-Source-Software
> FOSS Academy 5 Tage-Kompaktkurs „Sommerschule 2021“
> Jetzt anmelden:https://foss-academy.com/kompaktkurse/  
> *************************************************************
> WhereGroup GmbH
> Schwimmbadstr. 2
> 79100 Freiburg
> Germany
>
> Fon: +49 (0)761 / 519 102 - 61
> Fax: +49 (0)761 / 519 102 - 11
>
> stefan.giese at wheregroup.com
> www.wheregroup.com
> Geschäftsführer:
> Olaf Knopp, Peter Stamm
> Amtsgericht Bonn, HRB 9885
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210805/65dcedd3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hnhbbomilcpopckg.png
Type: image/png
Size: 10479 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210805/65dcedd3/attachment.png>


More information about the Qgis-user mailing list