[QGIS-Developer] QgsLayout.itemById returns wrong object

Nyall Dawson nyall.dawson at gmail.com
Sun Oct 21 16:26:01 PDT 2018


On Tue, 23 Jan 2018 at 22:34, Enrico Ferreguti <enricofer at gmail.com> wrote:
>
> I'm trying to programmatically set a QgsLayoutPicture content in QGIS3.0:
>
> 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
> myLayout = QgsProject.instance().layoutManager().layoutByName('test')
> myLayoutPicture = myLayout.itemById("picture")
> myLayoutPicture.setPicturePath("path to an image")
>
> and I get the following Exception:
> AttributeError: 'QgsLayoutItem' object has no attribute 'setPicturePath'
>
> If I inspect myLayoutPicture object I found it is a qgis._core.QgsLayoutItem not a QgsLayoutPicture
>
> Is this a correct behaviour or is it an issue? How can I get the right Layout object?

Coming back to this older discussion -- last week a workaround was
pushed to 3.3 master to try and avoid this issue. I'd love for
widespread testing of the currently nightlies to confirm that the
issue is now fixed (or not)! If anyone is still hitting this issue,
please report here the build number and what method you are calling to
retrieve a layout item.

Fingers crossed :) would be great to have this solved for 3.4!
Nyall


>
> Regards.
> Enrico Ferreguti
> _______________________________________________
> 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