[Qgis-user] Layout without initializeDefaults()

Mayo Rubiano mayo.rubianoh at gmail.com
Thu Feb 18 17:03:24 PST 2021


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.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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210218/95fdbea9/attachment.html>


More information about the Qgis-user mailing list