<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 23, 2018 at 1:34 PM, Enrico Ferreguti <span dir="ltr"><<a href="mailto:enricofer@gmail.com" target="_blank">enricofer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>I'm trying to programmatically set a QgsLayoutPicture content in QGIS3.0:</div><div><br></div><div>1) I create a new print composition and I name it 'test'<br></div>2) I create a picture frame in the composition and I call it 'picture'<br></div>3) I run the following code:</div><div><br></div><div>from qgis.core import QgsProject<br>myLayout = QgsProject.instance().<wbr>layoutManager().layoutByName('<wbr>test')<br>myLayoutPicture = myLayout.itemById("picture")<br></div></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>myLayoutPicture.<wbr>setPicturePath("path to an image")<br><br></div>and I get the following Exception:<br>AttributeError: 'QgsLayoutItem' object has no attribute 'setPicturePath'<br><br></div>If I inspect myLayoutPicture object I found it is a qgis._core.QgsLayoutItem not a QgsLayoutPicture<br><br></div>Is this a correct behaviour or is it an issue? How can I get the right Layout object?</div></div></blockquote><div><br></div><div>Yes, it is the correct behavior, the method returns  a pointer to the base class which is QgsLayoutItem.</div></div><div class="gmail_quote"><br></div><div class="gmail_quote">In the C++ API there is a template method to retrieve all objects of a certain type but it's not exposed to Python (that's not even possible with current SIP I think):</div><div class="gmail_quote"><br></div><div class="gmail_quote">template<class T> void layoutItems( QList<T *> &itemList ) const SIP_SKIP<br></div><div class="gmail_quote"></div><div class="gmail_quote"><br></div><div class="gmail_quote">Sorry but I don't have an answer to your last question.<br></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">Alessandro Pasotti<br>w3:   <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div>
</div></div>