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 本身始终定义为纵向。
可为布局定义最小页边距,但默认值通常为 0。当与 Qt 的打印支持结合使用时,最小页边距将反映打印机定义的最小可打印区域。
在默认的StandardMode 中,当前边距和最小边距始终会被考虑在内。可绘制的矩形是全页矩形减去当前边距,而当前边距只能设置为全页尺寸允许的最小边距和最大边距之间的值。
在FullPageMode 中,不考虑当前边距和最小边距。可绘制的矩形是整页的矩形,当前边距可以设置为任何值,与最小边距和页面大小无关。
另请参阅 QPageSize 。
成员类型文档
enum QPageLayout::Mode
定义页面布局模式
常数 | 值 | 说明 |
---|---|---|
QPageLayout::StandardMode | 0 | 绘制矩形包括边距,边距必须在最小值和最大值之间。 |
QPageLayout::FullPageMode | 1 | 绘制矩形不包括边距,边距可以是任何值,必须手动管理。 |
在标准模式(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 Points(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 Points(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)
Move-assignsother 到QPageLayout 实例,将托管指针的所有权转移到该实例。
QPageLayout &QPageLayout::operator=(const QPageLayout &other)
赋值运算符,为other 赋值。
相关非会员
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()。
© 2025 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.