[QGIS-Developer] QgsComposition.getComposerItemById returns wrong object

Enrico Ferreguti enricofer at gmail.com
Sat Jan 6 14:13:43 PST 2018


I'm trying to set programmatically a QgsComposerPicture content in QGIS2.99:

1) I create a new print composition and I name it 'test'
2) I create a picture frame in the composition and I call it 'picture'
3) I run the following code:

from qgis.core import QgsProject
myComposition =
QgsProject.instance().layoutManager().compositionByName('test')
myComposerPicture = myComposition.getComposerItemById("picture")
myComposerPicture.setPicturePath("[path to an image]")

and I get the following Exception:
AttributeError: 'QgsComposerItem' object has no attribute 'setPicturePath'

If I inspect myComposerPicture object I found it is a
qgis._core.QgsComposerItem not a QgsComposerPicture

Is this a correct behaviour or is it an issue?
Should I open a issue ticket?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180106/19d1fc6b/attachment.html>


More information about the QGIS-Developer mailing list