[Qgis-user] Layout page size variable?

John Layt j.layt at lparchaeology.com
Fri May 21 01:43:26 PDT 2021


Not sure you can use it in this case, but if you're needing to find
standard page sizes and localised names from width x height measurements,
the Qt QPageSize class has useful lookup tools. See
https://doc.qt.io/qt-5/qpagesize.html.

Something like:

    id = QPageSize.id(QSizeF(width, height), QPageSize.Millimeters)
    name = QPageSize.name(id)

It does a fuzzy match on size within 3 points, and ignores orientation, so
should always get the right standard page size regardless.

Cheers!

John.


On Thu, 20 May 2021 at 23:17, Tony Shepherd (FarmMaps NZ) <tony at farmmaps.nz>
wrote:

> Hi Charles (& others)
>
>
>
> Thanks for the advice guys.  I’ve come up with this, it works a treat.
>
>
>
> [%'Scale 1:' || format_number(round(map_get(item_variables('Main-Map-1'),
> 'map_scale'),0),0)||
>
> CASE
>
> WHEN @layout_pagewidth IS 297 AND @layout_pageheight IS 210 THEN ' @ A4'
>
> WHEN @layout_pagewidth IS 210 AND @layout_pageheight IS 297 THEN ' @ A4'
>
> WHEN @layout_pagewidth IS 420 AND @layout_pageheight IS 297 THEN ' @ A3'
>
> WHEN @layout_pagewidth IS 297 AND @layout_pageheight IS 420 THEN ' @ A3'
>
> ELSE ' @ ???'
>
> END%]
>
>
>
> Cheers
>
> Tony
>
>
>
> *From:* Charles Dixon-Paver <charles at kartoza.com>
> *Sent:* Friday, 21 May 2021 9:46 am
> *To:* Tony Shepherd (FarmMaps NZ) <tony at farmmaps.nz>
> *Cc:* qgis-user at lists.osgeo.org
> *Subject:* Re: [Qgis-user] Layout page size variable?
>
>
>
> Yeah I am not aware of a variable for this... But page sizes are actually
> more complicated than they seem. You can emulate it pretty easily with
> something like the following expression on a layout as you suggested:
>
>
>
> [%CASE
> WHEN @layout_pagewidth IS 297 AND @layout_pageheight IS 210 THEN 'On A4
> Landscape'
> WHEN @layout_pagewidth IS 210 AND @layout_pageheight IS 297 THEN 'On A4
> Portrait'
> WHEN @layout_pagewidth IS 420 AND @layout_pageheight IS 297 THEN 'On A3
> Landscape'
> WHEN @layout_pagewidth IS 297 AND @layout_pageheight IS 420 THEN 'On A3
> Portrait'
> ELSE 'With page dimensions of ' || @layout_pagewidth || ' x ' ||
> @layout_pageheight
> END%]
>
>
>
> On Thu, 20 May 2021 at 23:13, Tony Shepherd (FarmMaps NZ) <
> tony at farmmaps.nz> wrote:
>
> Hi All
>
>
>
> Is there a variable that returns the page size of a print layout?
>
>
>
> I would like to add the page size to the scale below so it reads something
> like “1:5,000 @ A3”
>
> I can see variables for width and height, but not Page Size?
>
>
>
> Or would I need to code in some ‘if’ &  ‘then’ statements using the width
> variables to arrive at the page size?
>
>
>
>
>
>
>
> Cheers
>
> Tony
>
>
>
> *Tony Shepherd*  *|*  GeoSpatial / Mapping Manager
>
> Ph 027 435 6193  *|*  E tony at farmmaps.nz
>
> FarmMaps NZ, 3 Kerwood Place, Gore 9740
>
>
>
> [image: FM_logo1_small (Custom)]
>
>
>
>
>
> <http://tonyshepherd8.wixsite.com/home>
> <https://www.wunderground.com/personal-weather-station/dashboard?ID=ISTLGORE2>
>
>
>
> _______________________________________________
> 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
>
> _______________________________________________
> 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/20210521/77d02d9a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 17917 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210521/77d02d9a/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 3062 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210521/77d02d9a/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 2467 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210521/77d02d9a/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 2510 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210521/77d02d9a/attachment-0002.png>


More information about the Qgis-user mailing list