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

Stefan Giese (WhereGroup) stefan.giese at wheregroup.com
Wed Aug 4 05:51:07 PDT 2021


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/20210804/15c11961/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/20210804/15c11961/attachment.png>


More information about the Qgis-user mailing list