QPageSize Class

The QPageSize class describes the size and name of a defined page size. More...

Header: #include <QPageSize>
qmake: QT += gui
Since: Qt 5.3

This class was introduced in Qt 5.3.

Public Types

enum PageSizeId { A0, A1, A2, A3, A4, 鈥�, LastPageSize }
enum SizeMatchPolicy { FuzzyMatch, FuzzyOrientationMatch, ExactMatch }
enum Unit { Millimeter, Point, Inch, Pica, Didot, Cicero }

Public Functions

QPageSize(const QPageSize &other)
QPageSize(const QSizeF &size, QPageSize::Unit units, const QString &name = QString(), QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)
QPageSize(const QSize &pointSize, const QString &name = QString(), QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)
QPageSize(QPageSize::PageSizeId pageSize)
QPageSize()
QPageSize &operator=(const QPageSize &other)
QPageSize &operator=(QPageSize &&other)
~QPageSize()
QSizeF definitionSize() const
QPageSize::Unit definitionUnits() const
QPageSize::PageSizeId id() const
bool isEquivalentTo(const QPageSize &other) const
bool isValid() const
QString key() const
QString name() const
QRectF rect(QPageSize::Unit units) const
QRect rectPixels(int resolution) const
QRect rectPoints() const
QSizeF size(QPageSize::Unit units) const
QSize sizePixels(int resolution) const
QSize sizePoints() const
void swap(QPageSize &other)
int windowsId() const

Static Public Members

QSizeF definitionSize(QPageSize::PageSizeId pageSizeId)
QPageSize::Unit definitionUnits(QPageSize::PageSizeId pageSizeId)
QPageSize::PageSizeId id(const QSize &pointSize, QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)
QPageSize::PageSizeId id(const QSizeF &size, QPageSize::Unit units, QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)
QPageSize::PageSizeId id(int windowsId)
QString key(QPageSize::PageSizeId pageSizeId)
QString name(QPageSize::PageSizeId pageSizeId)
QSizeF size(QPageSize::PageSizeId pageSizeId, QPageSize::Unit units)
QSize sizePixels(QPageSize::PageSizeId pageSizeId, int resolution)
QSize sizePoints(QPageSize::PageSizeId pageSizeId)
int windowsId(QPageSize::PageSizeId pageSizeId)
bool operator!=(const QPageSize &lhs, const QPageSize &rhs)
bool operator==(const QPageSize &lhs, const QPageSize &rhs)

Detailed Description

This class implements support for the set of standard page sizes as defined in the Adobe Postscript PPD Standard v4.3. It defines the standard set of page sizes in points, millimeters and inches and ensures these sizes are consistently used. Other size units can be used but will be calculated results and so may not always be consistent. The defined point sizes are always a integer, all other sizes can be fractions of a unit.

The defined size is always in width x height order with no implied page orientation. Note that it is possible for page sizes to be defined where the width is greater than the height, such as QPageSize::Ledger, so you cannot rely on comparing the width and height values to determine page orientation.

For example, A4 is defined by the standard as 210mm x 297mm, 8.27in x 11.69in, or 595pt x 842pt.

You can also define custom page sizes with custom names in any units you want and this unit size will be preserved and used as the base for all other unit size calculations.

When creating a QPageSize using a custom QSize you can choose if you want QPageSize to try match the size to a standard page size. By default QPaperSize uses a FuzzyMatch mode where it will match a given page size to a standard page size if it falls within 3 postscript points of a defined standard size. You can override this to request only an exact match but this is not recommended as conversions between units can easily lose 3 points and result in incorrect page sizes.

A QPageSize instance may also be obtained by querying the supported page sizes for a print device. In this case the localized name returned is that defined by the printer itself. Note that the print device may not support the current default locale language.

The class also provides convenience methods for converting page size IDs to and from various unit sizes.

See also QPagedPaintDevice and QPdfWriter.

Member Type Documentation

enum QPageSize::PageSizeId

This enum type lists the available page sizes as defined in the Postscript PPD standard. These values are duplicated in QPagedPaintDevice and QPrinter.

The defined sizes are:

ConstantValueDescription
QPageSize::A05841 x 1189 mm
QPageSize::A16594 x 841 mm
QPageSize::A27420 x 594 mm
QPageSize::A38297 x 420 mm
QPageSize::A40210 x 297 mm, 8.26 x 11.69 inches
QPageSize::A59148 x 210 mm
QPageSize::A610105 x 148 mm
QPageSize::A71174 x 105 mm
QPageSize::A81252 x 74 mm
QPageSize::A91337 x 52 mm
QPageSize::B0141000 x 1414 mm
QPageSize::B115707 x 1000 mm
QPageSize::B217500 x 707 mm
QPageSize::B318353 x 500 mm
QPageSize::B419250 x 353 mm
QPageSize::B51176 x 250 mm, 6.93 x 9.84 inches
QPageSize::B620125 x 176 mm
QPageSize::B72188 x 125 mm
QPageSize::B82262 x 88 mm
QPageSize::B92344 x 62 mm
QPageSize::B101631 x 44 mm
QPageSize::C5E24163 x 229 mm
QPageSize::Comm10E25105 x 241 mm, U.S. Common 10 Envelope
QPageSize::DLE26110 x 220 mm
QPageSize::Executive47.5 x 10 inches, 190.5 x 254 mm
QPageSize::Folio27210 x 330 mm
QPageSize::Ledger28431.8 x 279.4 mm
QPageSize::Legal38.5 x 14 inches, 215.9 x 355.6 mm
QPageSize::Letter28.5 x 11 inches, 215.9 x 279.4 mm
QPageSize::Tabloid29279.4 x 431.8 mm
QPageSize::Custom30Unknown, or a user defined size.
QPageSize::A1031聽
QPageSize::A3Extra32聽
QPageSize::A4Extra33聽
QPageSize::A4Plus34聽
QPageSize::A4Small35聽
QPageSize::A5Extra36聽
QPageSize::B5Extra37聽
QPageSize::JisB038聽
QPageSize::JisB139聽
QPageSize::JisB240聽
QPageSize::JisB341聽
QPageSize::JisB442聽
QPageSize::JisB543聽
QPageSize::JisB644,
QPageSize::JisB745聽
QPageSize::JisB846聽
QPageSize::JisB947聽
QPageSize::JisB1048聽
QPageSize::AnsiALetter= Letter
QPageSize::AnsiBLedger= Ledger
QPageSize::AnsiC49聽
QPageSize::AnsiD50聽
QPageSize::AnsiE51聽
QPageSize::LegalExtra52聽
QPageSize::LetterExtra53聽
QPageSize::LetterPlus54聽
QPageSize::LetterSmall55聽
QPageSize::TabloidExtra56聽
QPageSize::ArchA57聽
QPageSize::ArchB58聽
QPageSize::ArchC59聽
QPageSize::ArchD60聽
QPageSize::ArchE61聽
QPageSize::Imperial7x962聽
QPageSize::Imperial8x1063聽
QPageSize::Imperial9x1164聽
QPageSize::Imperial9x1265聽
QPageSize::Imperial10x1166聽
QPageSize::Imperial10x1367聽
QPageSize::Imperial10x1468聽
QPageSize::Imperial12x1169聽
QPageSize::Imperial15x1170聽
QPageSize::ExecutiveStandard71聽
QPageSize::Note72聽
QPageSize::Quarto73聽
QPageSize::Statement74聽
QPageSize::SuperA75聽
QPageSize::SuperB76聽
QPageSize::Postcard77聽
QPageSize::DoublePostcard78聽
QPageSize::Prc16K79聽
QPageSize::Prc32K80聽
QPageSize::Prc32KBig81聽
QPageSize::FanFoldUS82聽
QPageSize::FanFoldGerman83聽
QPageSize::FanFoldGermanLegal84聽
QPageSize::EnvelopeB485聽
QPageSize::EnvelopeB586聽
QPageSize::EnvelopeB687聽
QPageSize::EnvelopeC088聽
QPageSize::EnvelopeC189聽
QPageSize::EnvelopeC290聽
QPageSize::EnvelopeC391聽
QPageSize::EnvelopeC492聽
QPageSize::EnvelopeC5C5E= C5E
QPageSize::EnvelopeC693聽
QPageSize::EnvelopeC6594聽
QPageSize::EnvelopeC795聽
QPageSize::EnvelopeDLDLE= DLE
QPageSize::Envelope996聽
QPageSize::Envelope10Comm10E= Comm10E
QPageSize::Envelope1197聽
QPageSize::Envelope1298聽
QPageSize::Envelope1499聽
QPageSize::EnvelopeMonarch100聽
QPageSize::EnvelopePersonal101聽
QPageSize::EnvelopeChou3102聽
QPageSize::EnvelopeChou4103聽
QPageSize::EnvelopeInvite104聽
QPageSize::EnvelopeItalian105聽
QPageSize::EnvelopeKaku2106聽
QPageSize::EnvelopeKaku3107聽
QPageSize::EnvelopePrc1108聽
QPageSize::EnvelopePrc2109聽
QPageSize::EnvelopePrc3110聽
QPageSize::EnvelopePrc4111聽
QPageSize::EnvelopePrc5112聽
QPageSize::EnvelopePrc6113聽
QPageSize::EnvelopePrc7114聽
QPageSize::EnvelopePrc8115聽
QPageSize::EnvelopePrc9116聽
QPageSize::EnvelopePrc10117聽
QPageSize::EnvelopeYou4118聽
QPageSize::LastPageSizeEnvelopeYou4= EnvelopeYou4

Due to historic reasons QPageSize::Executive is not the same as the standard Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.

The Postscript standard size QPageSize::Folio is different to the Windows DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal if needed.

enum QPageSize::SizeMatchPolicy

ConstantValueDescription
QPageSize::FuzzyMatch0Match to a standard page size if within the margin of tolerance.
QPageSize::FuzzyOrientationMatch1Match to a standard page size if within the margin of tolerance regardless of orientation.
QPageSize::ExactMatch2Only match to a standard page size if the sizes match exactly.

enum QPageSize::Unit

This enum type is used to specify the measurement unit for page sizes.

ConstantValueDescription
QPageSize::Millimeter0聽
QPageSize::Point11/72th of an inch
QPageSize::Inch2聽
QPageSize::Pica31/72th of a foot, 1/6th of an inch, 12 Points
QPageSize::Didot41/72th of a French inch, 0.375 mm
QPageSize::Cicero51/6th of a French inch, 12 Didot, 4.5mm

Member Function Documentation

QPageSize::QPageSize(const QPageSize &other)

Copy constructor, copies other to this.

QPageSize::QPageSize(const QSizeF &size, QPageSize::Unit units, const QString &name = QString(), QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)

Creates a custom page of the given size in units.

If the given size matches a standard QPageSize::PageSizeId, then that page size will be used. Note that if the matchPolicy is FuzzyMatch this may result in the size being adjusted to the standard size. To prevent this happening use a matchPolicy of ExactMatch instead.

If the given size is not a standard QPageSize::PageSizeId then a QPageSize::Custom size will be created. The original unit size will be preserved and used as the base for all other unit size calculations.

If name is null then a custom name will be created in the form "Custom (width x height)" where the size is expressed in units provided.

QPageSize::QPageSize(const QSize &pointSize, const QString &name = QString(), QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)

Creates a QPageSize of the given pointSize in Points using the matching matchPolicy.

If the given pointSize matches a standard QPageSize::PageSizeId, then that page size will be used. Note that if the matchPolicy is FuzzyMatch this may result in the pointSize being adjusted to the standard size. To prevent this happening use a matchPolicy of ExactMatch instead.

If the given pointSize is not a standard QPageSize::PageSizeId then a QPageSize::Custom size will be created.

If name is null then the standard localized name will be used. If a custom page size then a custom name in the format "Custom (width x height)" will be created.

The matchPolicy defaults to FuzzyMatch.

QPageSize::QPageSize(QPageSize::PageSizeId pageSize)

Creates a QPageSize of the standard pageSize.

If pageSize is QPageSize::Custom then the resulting QPageSize will not be valid. Use the custom size constructor instead.

QPageSize::QPageSize()

Creates a null QPageSize.

QPageSize &QPageSize::operator=(const QPageSize &other)

Assignment operator, assigns other to this.

QPageSize &QPageSize::operator=(QPageSize &&other)

Move-assigns other to this QPageSize instance, transferring the ownership of the managed pointer to this instance.

QPageSize::~QPageSize()

Destroys the page.

QSizeF QPageSize::definitionSize() const

Returns the definition size of the page size.

For a standard page size this will be the size as defined in the relevant standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will be defined in inches.

For a custom page size this will be the original size used to create the page size object.

If the QPageSize is invalid then the QSizeF will be invalid.

See also definitionUnits().

[static] QSizeF QPageSize::definitionSize(QPageSize::PageSizeId pageSizeId)

Returns the definition size of the standard pageSizeId.

To obtain the definition units, call QPageSize::definitionUnits().

QPageSize::Unit QPageSize::definitionUnits() const

Returns the definition units of the page size.

For a standard page size this will be the units as defined in the relevant standard, i.e. ISO A4 will be defined in millimeters while ANSI Letter will be defined in inches.

For a custom page size this will be the original units used to create the page size object.

If the QPageSize is invalid then the QPageSize::Unit will be invalid.

See also definitionSize().

[static] QPageSize::Unit QPageSize::definitionUnits(QPageSize::PageSizeId pageSizeId)

Returns the definition units of the standard pageSizeId.

To obtain the definition size, call QPageSize::definitionSize().

QPageSize::PageSizeId QPageSize::id() const

Returns the standard QPageSize::PageSizeId of the page, or QPageSize::Custom.

If the QPageSize is invalid then the ID will be QPageSize::Custom.

[static] QPageSize::PageSizeId QPageSize::id(const QSize &pointSize, QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)

Returns the standard QPageSize::PageSizeId of the given pointSize in points using the given matchPolicy.

If using FuzzyMatch then the point size of the PageSizeId returned may not exactly match the pointSize you passed in. You should call QPageSize::sizePoints() using the returned PageSizeId to find out the actual point size of the PageSizeId before using it in any calculations.

[static] QPageSize::PageSizeId QPageSize::id(const QSizeF &size, QPageSize::Unit units, QPageSize::SizeMatchPolicy matchPolicy = FuzzyMatch)

Returns the standard QPageSize::PageSizeId of the given size in units using the given matchPolicy.

If using FuzzyMatch then the unit size of the PageSizeId returned may not exactly match the size you passed in. You should call QPageSize::size() using the returned PageSizeId to find out the actual unit size of the PageSizeId before using it in any calculations.

[static] QPageSize::PageSizeId QPageSize::id(int windowsId)

Returns the PageSizeId for the given Windows DMPAPER enum value windowsId.

If there is no matching PageSizeId then QPageSize::Custom is returned.

bool QPageSize::isEquivalentTo(const QPageSize &other) const

Returns true if this page is equivalent to the other page, i.e. if the page has the same size regardless of other attributes like name.

bool QPageSize::isValid() const

Returns true if this page size is valid.

The page size may be invalid if created with an invalid PageSizeId, or a negative or invalid QSize or QSizeF, or the null constructor.

QString QPageSize::key() const

Returns the unique key of the page size.

By default this is the PPD standard mediaOption keyword for the page size, or the PPD custom format key. If the QPageSize instance was obtained from a print device then this will be the key provided by the print device and may differ from the standard key.

If the QPageSize is invalid then the key will be an empty string.

This key should never be shown to end users, it is an internal key only. For a human-readable name use name().

See also name().

[static] QString QPageSize::key(QPageSize::PageSizeId pageSizeId)

Returns the PPD mediaOption keyword of the standard pageSizeId.

If the QPageSize is invalid then the key will be empty.

QString QPageSize::name() const

Returns a localized human-readable name for the page size.

If the QPageSize instance was obtained from a print device then the name used is that provided by the print device. Note that a print device may not support the current default locale language.

If the QPageSize is invalid then the name will be an empty string.

[static] QString QPageSize::name(QPageSize::PageSizeId pageSizeId)

Returns the localized name of the standard pageSizeId.

If the QPageSize is invalid then the name will be empty.

QRectF QPageSize::rect(QPageSize::Unit units) const

Returns the page rectangle in the required units.

If the QPageSize is invalid then the QRect will be invalid.

QRect QPageSize::rectPixels(int resolution) const

Returns the page rectangle in Device Pixels at the given resolution.

If the QPageSize is invalid then the QRect will be invalid.

QRect QPageSize::rectPoints() const

Returns the page rectangle in Postscript Points (1/72 of an inch).

If the QPageSize is invalid then the QRect will be invalid.

QSizeF QPageSize::size(QPageSize::Unit units) const

Returns the size of the page in the required units.

If the QPageSize is invalid then the QSizeF will be invalid.

[static] QSizeF QPageSize::size(QPageSize::PageSizeId pageSizeId, QPageSize::Unit units)

Returns the size of the standard pageSizeId in the requested units.

QSize QPageSize::sizePixels(int resolution) const

Returns the size of the page in Device Pixels at the given resolution.

If the QPageSize is invalid then the QSize will be invalid.

[static] QSize QPageSize::sizePixels(QPageSize::PageSizeId pageSizeId, int resolution)

Returns the size of the standard pageSizeId in Device Pixels for the given resolution.

QSize QPageSize::sizePoints() const

Returns the size of the page in Postscript Points (1/72 of an inch).

If the QPageSize is invalid then the QSize will be invalid.

[static] QSize QPageSize::sizePoints(QPageSize::PageSizeId pageSizeId)

Returns the size of the standard pageSizeId in Points.

void QPageSize::swap(QPageSize &other)

Swaps this QPageSize with other. This function is very fast and never fails.

int QPageSize::windowsId() const

Returns the Windows DMPAPER enum value for the page size.

Not all valid PPD page sizes have a Windows equivalent, in which case 0 will be returned.

If the QPageSize is invalid then the Windows ID will be 0.

See also id().

[static] int QPageSize::windowsId(QPageSize::PageSizeId pageSizeId)

Returns the Windows DMPAPER enum value of the standard pageSizeId.

Not all valid PPD page sizes have a Windows equivalent, in which case 0 will be returned.

Related Non-Members

bool operator!=(const QPageSize &lhs, const QPageSize &rhs)

Returns true if page size lhs is unequal to page size rhs, i.e. if the page size has different attributes. Current attributes are size and name.

bool operator==(const QPageSize &lhs, const QPageSize &rhs)

Returns true if page size lhs is equal to page size rhs, i.e. if the page sizes have the same attributes. Current attributes are size and name.

漏 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.