[Qgis-user] Layout without initializeDefaults()

Nyall Dawson nyall.dawson at gmail.com
Thu Feb 18 17:08:36 PST 2021


On Fri, 19 Feb 2021 at 11:03, Mayo Rubiano <mayo.rubianoh at gmail.com> wrote:
>
> Hello everyone.
> I'm new in QGIS.
> My question is: I'm trying to layout with PYQGIS, I understand that there is one way to initialize automatically the layout configurations that is with the function initializeDefaluts(), that adds a A4 page in landscape orientation. But I want to layout without this function because I need a different page size and orientation.
> I tried with this code in the python console:
>
> project = QgsProject().instance()
> layout = QgsPrintLayout(project)
> page = QgsLayoutItemPage(layout)
> #set page orientation vertically and a letter size
> page.setPageSize("Letter", 0)

layout.pageCollection().addPage( page )

(you don't use addLayoutItem for pages -- add it directly to the page
collection instead)

Nyall


> layout.addLayoutItem(page)
> #set the layout name for the layout manager
> layout.setName("MyLayout")
> #add the layout to the layout manager
> project.layoutManager().addLayout(layout)
>
>
> When I open the layout made with this code in the the layout manager I note that the variable layout_numpages is set to 0, that means that I can't add guides because there are no pages to link guides and I can't use the rulers because the 0 of y rulers is at the coordinates (0,10)mm. Then, there are other variables with different values (layout_pageheight, layout_pageoffset and layout _page width).
>
> Could someone tell me what is needed to build a layout without that function and correcting the rulers and the layout_numpage variable?
>
> Thanks
>
> M. Rubiano
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the Qgis-user mailing list