[QGIS-Developer] QgsComposition.getComposerItemById returns wrong object

Nyall Dawson nyall.dawson at gmail.com
Sat Jan 6 17:08:54 PST 2018


On 7 January 2018 at 08:13, Enrico Ferreguti <enricofer at gmail.com> wrote:
> 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?

If your script is targeting QGIS 3.0, please don't file bugs against
composer. You need to use the newer layouts engine instead (QgsLayout
and associated classes).

Over the coming week all composer code will be removed from QGIS.

Nyall

>
>
> _______________________________________________
> 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