[QGIS-Developer] Problem with copying layout's items from a printlayout template to another printlayout template in python

patrycja.tatar@wp.pl patrycja.tatar at wp.pl
Thu May 25 11:04:08 PDT 2023


Hi, I'm trying to create a qgis plugin in python. And I have a problem with coping layout's items from one printlayout template to another printlayout template.   When I execute this code:     composition.loadFromTemplate(doc, QgsReadWriteContext(), True)          composition.setName(layoutName)           layout_model_name = "LayoutNameModel"          layout_model = project.layoutManager().layoutByName(layout_model_name)           if layout_model is not None:              all_items = layout_wzor.items()              for item in all_items:                  if isinstance(item, QgsLayoutItemPolyline) or isinstance(item, QgsLayoutItemPicture) or isinstance(item, QgsLayoutItemMap) or isinstance(item, QgsLayoutItemLegend):                      composition.addItem(item_new)    I lose map's focus during exporting to pdf.   And when I execute this code:           layout_name1 = 'Name_First_Layout'          layout1 = project.layoutManager().layoutByName(layout_name1)           layout_name2 = 'Name_Second_Layout'          layout2 = project.layoutManager().layoutByName(layout_name2)           item_name = 'Map 1'          item1 = layout1.itemById(item_name)            if item1 and isinstance(item1, QgsLayoutItemMap):              item2 = QgsLayoutItemMap(layout2)              item2.setRect(item1.rect())               item2.setLayers(item1.layers())              item2.setExtent(item1.extent())              item2.setScale(item1.scale())               layout2.addLayoutItem(item2)    The map suddenly disappears from the printlayout during export and is not visible in the pdf file. Although it is visible on list of objects on the right side of the layout.   Maybe you have some idea how to solve this problem?   Thank you for your help ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230525/53fc960b/attachment.htm>


More information about the QGIS-Developer mailing list