QPageLayout Class
描述页面的尺寸、方向和边距。更多...
| 页眉: | #include <QPageLayout> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
公共类型
| enum | Mode { StandardMode, FullPageMode } |
| enum | Orientation { Portrait, Landscape } |
(since 6.8) enum class | OutOfBoundsPolicy { Reject, Clamp } |
| enum | Unit { Millimeter, Point, Inch, Pica, Didot, Cicero } |
公共函数
| QPageLayout() | |
| QPageLayout(const QPageSize &pageSize, QPageLayout::Orientation orientation, const QMarginsF &margins, QPageLayout::Unit units = Point, const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0)) | |
| QPageLayout(const QPageLayout &other) | |
| ~QPageLayout() | |
| QRectF | fullRect() const |
| QRectF | fullRect(QPageLayout::Unit units) const |
| QRect | fullRectPixels(int resolution) const |
| QRect | fullRectPoints() const |
| bool | isEquivalentTo(const QPageLayout &other) const |
| bool | isValid() const |
| QMarginsF | margins() const |
| QMarginsF | margins(QPageLayout::Unit units) const |
| QMargins | marginsPixels(int resolution) const |
| QMargins | marginsPoints() const |
| QMarginsF | maximumMargins() const |
| QMarginsF | minimumMargins() const |
| QPageLayout::Mode | mode() const |
| QPageLayout::Orientation | orientation() const |
| QPageSize | pageSize() const |
| QRectF | paintRect() const |
| QRectF | paintRect(QPageLayout::Unit units) const |
| QRect | paintRectPixels(int resolution) const |
| QRect | paintRectPoints() const |
| bool | setBottomMargin(qreal bottomMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject) |
| bool | setLeftMargin(qreal leftMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject) |
| bool | setMargins(const QMarginsF &margins, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject) |
| void | setMinimumMargins(const QMarginsF &minMargins) |
| void | setMode(QPageLayout::Mode mode) |
| void | setOrientation(QPageLayout::Orientation orientation) |
| void | setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0)) |
| bool | setRightMargin(qreal rightMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject) |
| bool | setTopMargin(qreal topMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject) |
| void | setUnits(QPageLayout::Unit units) |
| void | swap(QPageLayout &other) |
| QPageLayout::Unit | units() const |
| QPageLayout & | operator=(QPageLayout &&other) |
| QPageLayout & | operator=(const QPageLayout &other) |
相关的非成员项
| bool | operator!=(const QPageLayout &lhs, const QPageLayout &rhs) |
| bool | operator==(const QPageLayout &lhs, const QPageLayout &rhs) |
详细说明
QPageLayout 类定义了分页文档中页面的布局,可以设置页面大小、方向和边距,并能以多种单位查询由这些属性定义的整个页面和可绘制页面矩形。
页面大小由QPageSize 类定义,可通过该类查询页面大小属性。请注意,QPageSize 本身始终定义为纵向(Portrait)方向。
布局可定义最小页边距,但通常默认值为 0。当与 Qt Print Support 结合使用时,最小页边距将反映打印机定义的最小可打印区域。
在默认的 `StandardMode ` 中,当前页边距和最小页边距始终会被考虑在内。可绘制矩形等于整页矩形减去当前页边距,且当前页边距只能设置为介于最小页边距与整页尺寸允许的最大页边距之间的值。
在FullPageMode 中,不会考虑当前页边距和最小页边距。可绘制矩形即为整页矩形,且当前页边距可设置为任意值,不受最小页边距和页面大小的限制。
另请参阅 QPageSize 。
成员类型文档
enum QPageLayout::Mode
定义页面布局模式
| 常量 | 值 | 描述 |
|---|---|---|
QPageLayout::StandardMode | 0 | “Paint Rect” 包含边距,边距值必须介于最小值和最大值之间。 |
QPageLayout::FullPageMode | 1 | “Paint Rect” 不包含边距,边距可以是任意值,且必须手动管理。 |
在 StandardMode 下,设置边距时,请使用 `Clamp ` 自动将边距限制在允许的最小值和最大值之间。
另请参阅 ` OutOfBoundsPolicy`。
enum QPageLayout::Orientation
此枚举类型定义了页面方向
| 常量 | 值 | 描述 |
|---|---|---|
QPageLayout::Portrait | 0 | 页面大小用于其默认方向 |
QPageLayout::Landscape | 1 | 页面尺寸旋转了 90 度 |
请注意,某些标准页面尺寸的宽度大于高度,因此其方向是相对于标准页面尺寸定义的,而非基于相对页面尺寸。
[since 6.8] enum class QPageLayout::OutOfBoundsPolicy
定义了超出边界的边距的处理策略
| 常量 | 值 | 描述 |
|---|---|---|
QPageLayout::OutOfBoundsPolicy::Reject | 0 | 边距必须在最小值和最大值范围内,否则将被拒绝。 |
QPageLayout::OutOfBoundsPolicy::Clamp | 1 | 边距被限制在最小值和最大值之间,以确保其有效性。 注意: 在FullPageMode 中,该 策略无效,该模式下所有页边距均被接受。 |
该枚举类型自 Qt 6.8 起引入。
enum QPageLayout::Unit
此枚举类型用于指定页面布局和边距的测量单位。
| 常量 | 值 | 描述 |
|---|---|---|
QPageLayout::Millimeter | 0 | |
QPageLayout::Point | 1 | 1/72英寸 |
QPageLayout::Inch | 2 | |
QPageLayout::Pica | 3 | 1/72英尺,1/6英寸,12点 |
QPageLayout::Didot | 4 | 1/72法式英寸,0.375毫米 |
QPageLayout::Cicero | 5 | 1/6法式英寸,12迪多,4.5毫米 |
成员函数文档
QPageLayout::QPageLayout()
创建了一个无效的 QPageLayout。
QPageLayout::QPageLayout(const QPageSize &pageSize, QPageLayout::Orientation orientation, const QMarginsF &margins, QPageLayout::Unit units = Point, const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0))
在给定的units 中,使用给定的pageSize 、orientation 和margins 创建一个QPageLayout。
可选地定义允许的最小边距minMargins ,例如物理打印设备能够打印的最小边距。
生成的 QPageLayout 将位于StandardMode 中。
给定的margins 将被限制在页面尺寸允许的最小边距和最大边距之间。
QPageLayout::QPageLayout(const QPageLayout &other)
复制构造函数,将other 复制到this中。
[noexcept] QPageLayout::~QPageLayout()
破坏了页面布局。
QRectF QPageLayout::fullRect() const
返回以当前布局单位表示的完整页面矩形。
该页面矩形考虑了页面大小和页面方向,但不考虑页面边距。
QRectF QPageLayout::fullRect(QPageLayout::Unit units) const
返回符合指定units 要求的完整页面矩形。
该页面矩形会考虑页面大小和页面方向,但不考虑页面边距。
另请参阅 paintRect()。
QRect QPageLayout::fullRectPixels(int resolution) const
返回给定resolution 的完整页面矩形(以设备像素为单位)。
该页面矩形会考虑页面大小和页面方向,但不考虑页面边距。
另请参阅 paintRect()。
QRect QPageLayout::fullRectPoints() const
返回以PostScript点(1/72英寸)为单位的完整页面矩形。
该页面矩形考虑了页面尺寸和页面方向,但不考虑页面边距。
另请参阅 paintRect()。
bool QPageLayout::isEquivalentTo(const QPageLayout &other) const
如果该页面布局与other 页面布局等同(即该页面的尺寸、边距和方向与之相同),则返回true 。
bool QPageLayout::isValid() const
如果此页面布局有效,则返回true 。
QMarginsF QPageLayout::margins() const
使用当前设定的单位返回页面布局的页边距。
另请参阅 setMargins() 和units()。
QMarginsF QPageLayout::margins(QPageLayout::Unit units) const
使用请求的units 返回页面布局的边距。
另请参阅 setMargins() 和margins()。
QMargins QPageLayout::marginsPixels(int resolution) const
返回给定resolution 的页面布局边距(以设备像素为单位)。
另请参阅 setMargins()。
QMargins QPageLayout::marginsPoints() const
返回页面布局的边距,单位为Postscript点(1/72英寸)。
另请参阅 setMargins() 和margins()。
QMarginsF QPageLayout::maximumMargins() const
返回如果页面布局采用StandardMode 时将应用的最大边距。
允许的最大边距计算方式为:页面总尺寸减去已设置的最小边距。例如,如果页面宽度为 100 点,且最小右边距为 10 点,则最大左边距为 90 点。
另请参阅 setMinimumMargins() 和minimumMargins()。
QMarginsF QPageLayout::minimumMargins() const
返回页面布局的最小边距。
另请参阅 setMinimumMargins() 和maximumMargins()。
QPageLayout::Mode QPageLayout::mode() const
返回页面布局模式。
另请参阅 ` setMode()`。
QPageLayout::Orientation QPageLayout::orientation() const
返回页面布局的页面方向。
另请参阅 setOrientation()。
QPageSize QPageLayout::pageSize() const
返回页面布局的页面尺寸。
请注意,QPageSize 始终以纵向模式定义。若要获取考虑了当前设置的页面方向的尺寸,必须使用fullRect()。
另请参阅 setPageSize()。
QRectF QPageLayout::paintRect() const
返回以当前布局单位表示的页面矩形。
可绘制矩形会考虑页面大小、方向和边距。
如果设置了FullPageMode 模式,则返回fullRect(),且必须手动管理边距。
QRectF QPageLayout::paintRect(QPageLayout::Unit units) const
返回符合指定units 要求的页面矩形。
可绘制矩形会考虑页面大小、方向和边距。
如果设置了FullPageMode 模式,则会返回fullRect(),此时必须手动管理边距。
QRect QPageLayout::paintRectPixels(int resolution) const
返回给定resolution 对应的、以四舍五入的设备像素为单位的可绘制矩形。
该可绘制矩形会考虑页面大小、方向和边距。
如果启用了FullPageMode 模式,则会返回fullRect(),此时必须手动管理边距。
QRect QPageLayout::paintRectPoints() const
返回以四舍五入的PostScript点(1/72英寸)为单位的可绘制矩形。
可绘制矩形会考虑页面大小、方向和边距。
如果启用了FullPageMode 模式,则返回fullRect(),此时必须手动管理页边距。
bool QPageLayout::setBottomMargin(qreal bottomMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject)
将页面布局的底部页边距设置为bottomMargin 。如果边距设置成功,则返回true。
所使用的单位为当前布局中定义的单位。若要使用其他单位,请先调用setUnits()。
自 Qt 6.8 起,可使用可选参数outOfBoundsPolicy 来指定如何处理超出边界的边距。
另请参阅 setMargins() 和margins()。
bool QPageLayout::setLeftMargin(qreal leftMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject)
将页面布局的左页边距设置为leftMargin 。如果边距设置成功,则返回true。
所使用的单位为当前布局中定义的单位。若要使用其他单位,请先调用setUnits()。
自 Qt 6.8 起,可选参数 `outOfBoundsPolicy ` 可用于指定超出边界的页边距的处理方式。
另请参阅 setMargins() 和margins()。
bool QPageLayout::setMargins(const QMarginsF &margins, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject)
将页面布局的页边距设置为margins 。如果页边距设置成功,则返回true。
所使用的单位为当前布局中定义的单位。若要使用其他单位,请先调用setUnits()。
自 Qt 6.8 起,可使用可选参数outOfBoundsPolicy 来指定如何处理超出边界的页边距。
void QPageLayout::setMinimumMargins(const QMarginsF &minMargins)
将页面布局的最小页边距设置为minMargins 。
不建议覆盖为页面大小设置的默认值,因为这可能是物理打印设备的最小可打印区域。
如果设置了“StandardMode ”模式,则现有页边距将被限制在新的minMargins 和页面大小允许的最大值之间。如果设置了“FullPageMode ”,则现有页边距将保持不变。
另请参阅 minimumMargins() 和setMargins()。
void QPageLayout::setMode(QPageLayout::Mode mode)
将页面布局模式设置为mode 。
另请参阅 mode()。
void QPageLayout::setOrientation(QPageLayout::Orientation orientation)
将页面布局的页面方向设置为orientation 。
更改页面方向不会影响当前的页边距或最小页边距。
另请参阅 orientation()。
void QPageLayout::setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins = QMarginsF(0, 0, 0, 0))
将页面布局的页面大小设置为pageSize 。
可选地定义允许的最小页边距minMargins ,例如物理打印设备能够打印的最小页边距;否则,最小页边距将默认为0。
如果设置了StandardMode ,则现有页边距将被限制在新的最小页边距与页面大小允许的最大页边距之间。如果设置了FullPageMode ,则现有页边距将保持不变。
另请参阅 pageSize()。
bool QPageLayout::setRightMargin(qreal rightMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject)
将页面布局的右页边距设置为rightMargin 。如果边距设置成功,则返回true。
所使用的单位为当前布局中定义的单位。若要使用其他单位,请先调用setUnits()。
自 Qt 6.8 起,可选参数outOfBoundsPolicy 可用于指定超出边界的页边距应如何处理。
另请参阅 setMargins() 和margins()。
bool QPageLayout::setTopMargin(qreal topMargin, QPageLayout::OutOfBoundsPolicy outOfBoundsPolicy = OutOfBoundsPolicy::Reject)
将页面布局的顶部页边距设置为topMargin 。如果页边距设置成功,则返回true。
所使用的单位为当前布局中定义的单位。若要使用其他单位,请先调用setUnits()。
自 Qt 6.8 起,可选参数 `outOfBoundsPolicy ` 可用于指定超出边界的页边距应如何处理。
另请参阅 setMargins() 和margins()。
void QPageLayout::setUnits(QPageLayout::Unit units)
设置用于定义页面布局的units 。
另请参阅 units()。
[noexcept] void QPageLayout::swap(QPageLayout &other)
将此页面布局替换为other 。此操作速度极快,且从不会失败。
QPageLayout::Unit QPageLayout::units() const
返回页面布局当前定义的单位。
另请参阅 setUnits()。
[noexcept] QPageLayout &QPageLayout::operator=(QPageLayout &&other)
将other 通过move赋值给此QPageLayout 实例,从而将该管理指针的所有权转移至该实例。
QPageLayout &QPageLayout::operator=(const QPageLayout &other)
赋值运算符,将other 赋值给this。
相关的非成员
bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs)
如果页面布局lhs 与页面布局rhs 不相等,即两者中的任何属性存在差异,则返回true 。
请注意,这是严格的相等比较,特别是对于页面大小,其QPageSize 的 ID、名称和大小必须完全匹配;对于边距,其单位必须一致。
另请参阅 QPageLayout::isEquivalentTo()。
bool operator==(const QPageLayout &lhs, const QPageLayout &rhs)
如果页面布局lhs 与页面布局rhs 相等,即所有属性完全相等,则返回true 。
请注意,这里要求严格相等,特别是对于页面大小,其QPageSize 的 ID、名称和大小必须完全一致;对于页边距,其单位必须一致。
另请参阅 QPageLayout::isEquivalentTo()。
© 2026 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.