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

Thomas Gratier osgeo.mailinglist at gmail.com
Sun Jan 2 13:02:19 PST 2022


Hi,

Hope the following will be more understandable from a non-coder

# Below tell you how many entries (QgsPageSize) are already present (A4,
A3, ...) before
print(len(pageSizeRegistry.entries()))
# To inspect content of first entry (was useful to understand was is
present in each QgsPageSize)
print(pageSizeRegistry.entries()[0].size)
print(pageSizeRegistry.entries()[0].displayName)
print(pageSizeRegistry.entries()[0].name)

You could run also run the following to see all infos for all preset formats

for entry in pageSizeRegistry.entries():
    print("Size: ", entry.size)
    print(f"EncodedSize: {entry.size.encodeSize()}")
    print(f"DisplayName: {entry.displayName}")
    print(f"Name: {entry.name}")

Testing after adding the part `pageSizeRegistry.add(...` show you have now
one more entry compare to before
print(len(pageSizeRegistry.entries()))

Regards

Thomas


Le dim. 2 janv. 2022 à 21:16, Christophe Besuchet <design at golok.net> a
écrit :

> 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> 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
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: 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/70164b85/attachment.html>


More information about the Qgis-user mailing list