[Qgis-user] Custom preset format page for print layouts

Christophe Besuchet design at golok.net
Sun Jan 2 12:11:18 PST 2022


Hi Thomas,

Thanks a bunch for your answer and your code. It works like a charm!

However, I'm really bad at coding and I'm not sure why some lines are commented; since your code works without uncommenting these lines, can you tell me what's their purpose?

Cheers,

Golok

> On 2 Jan 2022, at 18:00, Thomas Gratier <osgeo.mailinglist at gmail.com> wrote:
> 
> Hi,
> 
> In startup.py, add the following to register your custom Custom preset format page for print layouts.
> 
> 
> from qgis.core import QgsApplication, QgsPageSize, QgsLayoutSize, QgsUnitTypes
> 
> pageSizeRegistry = QgsApplication.pageSizeRegistry()
> 
> # For demo purpose in PyQGIS, so commented
> # print(len(pageSizeRegistry.entries()))
> # print(pageSizeRegistry.entries()[0].size)
> # print(pageSizeRegistry.entries()[0].displayName)
> # print(pageSizeRegistry.entries()[0].name)
> 
> # You will see in the menu, myDisplayName with other default preset format pages after executing the following line
> pageSizeRegistry.add(QgsPageSize('myname', QgsLayoutSize(150, 100, units=QgsUnitTypes.LayoutMillimeters), 'myDisplayName'))
> 
> # print(len(pageSizeRegistry.entries()))
> 
> Cheers
> 
> Thomas Gratier
> 
> Le mer. 29 déc. 2021 à 19:50, Christophe Besuchet <design at golok.net <mailto:design at golok.net>> a écrit :
> Hello all,
> 
> I'm often using the same custom page size in my print layouts, and I created several templates for this.
> 
> However, if I have to add a new page, the later won't inherit my template's format settings; the Size menu will only propose standard presets and I will have to set the size manually (and the guides as well).
> 
> Is there a way to create and save custom preset format pages so they will show up in the Size menu?
> 
> In advance thank you for your help!
> 
> Golok
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user <https://lists.osgeo.org/mailman/listinfo/qgis-user>
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user <https://lists.osgeo.org/mailman/listinfo/qgis-user>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220102/d9b47512/attachment.html>


More information about the Qgis-user mailing list