QRectF Class
QRectF 类使用浮点精度在平面上定义了一个有限矩形。更多内容...
| 头文件: | #include <QRectF> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- 所有成员的列表,包括继承的成员
- QRectF 属于绘图类。
注意:该类中的所有函数均为可重入函数。
QRectF 比较
| 类别 | 可比较类型 |
|---|---|
| 相等性 | QRectF |
| 相等性 | QRect. |
公共函数
| QRectF() | |
| QRectF(const QRect &rectangle) | |
| QRectF(const QPointF &topLeft, const QPointF &bottomRight) | |
| QRectF(const QPointF &topLeft, const QSizeF &size) | |
| QRectF(qreal x, qreal y, qreal width, qreal height) | |
| void | adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2) |
| QRectF | adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const |
| qreal | bottom() const |
| QPointF | bottomLeft() const |
| QPointF | bottomRight() const |
| QPointF | center() const |
| bool | contains(const QPointF &point) const |
| bool | contains(const QRectF &rectangle) const |
| bool | contains(qreal x, qreal y) const |
| void | getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const |
| void | getRect(qreal *x, qreal *y, qreal *width, qreal *height) const |
| qreal | height() const |
| QRectF | intersected(const QRectF &rectangle) const |
| bool | intersects(const QRectF &rectangle) const |
| bool | isEmpty() const |
| bool | isNull() const |
| bool | isValid() const |
| qreal | left() const |
| QRectF | marginsAdded(const QMarginsF &margins) const |
| QRectF | marginsRemoved(const QMarginsF &margins) const |
| void | moveBottom(qreal y) |
| void | moveBottomLeft(const QPointF &position) |
| void | moveBottomRight(const QPointF &position) |
| void | moveCenter(const QPointF &position) |
| void | moveLeft(qreal x) |
| void | moveRight(qreal x) |
| void | moveTo(qreal x, qreal y) |
| void | moveTo(const QPointF &position) |
| void | moveTop(qreal y) |
| void | moveTopLeft(const QPointF &position) |
| void | moveTopRight(const QPointF &position) |
| QRectF | normalized() const |
| qreal | right() const |
| void | setBottom(qreal y) |
| void | setBottomLeft(const QPointF &position) |
| void | setBottomRight(const QPointF &position) |
| void | setCoords(qreal x1, qreal y1, qreal x2, qreal y2) |
| void | setHeight(qreal height) |
| void | setLeft(qreal x) |
| void | setRect(qreal x, qreal y, qreal width, qreal height) |
| void | setRight(qreal x) |
| void | setSize(const QSizeF &size) |
| void | setTop(qreal y) |
| void | setTopLeft(const QPointF &position) |
| void | setTopRight(const QPointF &position) |
| void | setWidth(qreal width) |
| void | setX(qreal x) |
| void | setY(qreal y) |
| QSizeF | size() const |
| QRect | toAlignedRect() const |
| CGRect | toCGRect() const |
(since 6.5) emscripten::val | toDOMRect() const |
| QRect | toRect() const |
| qreal | top() const |
| QPointF | topLeft() const |
| QPointF | topRight() const |
| void | translate(qreal dx, qreal dy) |
| void | translate(const QPointF &offset) |
| QRectF | translated(qreal dx, qreal dy) const |
| QRectF | translated(const QPointF &offset) const |
| QRectF | transposed() const |
| QRectF | united(const QRectF &rectangle) const |
| qreal | width() const |
| qreal | x() const |
| qreal | y() const |
| QRectF | operator&(const QRectF &rectangle) const |
| QRectF & | operator&=(const QRectF &rectangle) |
| QRectF & | operator+=(const QMarginsF &margins) |
| QRectF & | operator-=(const QMarginsF &margins) |
| QRectF | operator|(const QRectF &rectangle) const |
| QRectF & | operator|=(const QRectF &rectangle) |
静态公共成员
| QRectF | fromCGRect(CGRect rect) |
(since 6.5) QRectF | fromDOMRect(emscripten::val domRect) |
相关的非成员
(since 6.8) bool | qFuzzyCompare(const QRectF &lhs, const QRectF &rhs) |
(since 6.8) bool | qFuzzyIsNull(const QRectF &rect) |
| bool | operator!=(const QRectF &lhs, const QRectF &rhs) |
| QRectF | operator+(const QRectF &lhs, const QMarginsF &rhs) |
| QRectF | operator+(const QMarginsF &lhs, const QRectF &rhs) |
| QRectF | operator-(const QRectF &lhs, const QMarginsF &rhs) |
| QDataStream & | operator<<(QDataStream &stream, const QRectF &rectangle) |
| bool | operator==(const QRectF &lhs, const QRectF &rhs) |
| QDataStream & | operator>>(QDataStream &stream, QRectF &rectangle) |
详细说明
矩形通常由左上角坐标和尺寸来表示。QRectF 的尺寸(宽度和高度)始终与其渲染所依据的数学矩形相等。
可以通过一组左、上、宽和高的坐标来构造一个 QRectF,或者通过一个QPointF 和一个QSizeF 来构造。以下代码创建了两个相同的矩形。
此外,还有第三个构造函数,可从QRect 创建一个QRectF,以及相应的toRect()函数,该函数根据该矩形的值返回一个QRect 对象(请注意,返回矩形中的坐标会四舍五入到最接近的整数)。
QRectF类提供了一组函数,这些函数可返回矩形的各种坐标,并允许对这些坐标进行操作。 QRectF 还提供了用于相对于各种坐标移动矩形的函数。此外,还有moveTo() 函数,该函数在保持矩形左上角位于给定坐标不变的情况下移动矩形。另外,translate() 函数将矩形相对于当前位置移动给定的偏移量,而translated() 函数则返回该矩形经平移后的副本。
size() 函数返回矩形的尺寸,返回类型为QSizeF 。也可以通过width() 和height() 函数分别获取尺寸。要操作尺寸,请使用setSize()、setWidth() 或setHeight() 函数。此外,还可以通过调用设置矩形坐标的函数(例如setBottom() 或setRight())来更改尺寸。
contains() 函数用于判断给定点是否位于矩形内部;intersects() 函数若该矩形与给定矩形相交,则返回true (否则返回 false)。QRectF 类还提供了intersected() 函数,该函数返回相交矩形;以及united() 函数,该函数返回同时包含给定矩形和当前矩形的包围矩形:
isEmpty() 函数若矩形的宽度或高度小于或等于 0,则返回true 。请注意,空矩形是不合法的:若宽度和高度均大于 0,则isValid() 函数返回true 。另一方面,空矩形(isNull() == true)的宽度和高度均设为 0。
请注意,由于QRect 和 QRectF 的定义方式,空的 QRectF 实际上与QRect 的定义方式基本相同。
最后,QRectF 对象既可以进行流式传输,也可以进行比较。
渲染
使用anti-aliased 绘图器时,QRectF 的边界线将对称地渲染在数学矩形边界线的两侧。但使用锯齿绘图器(默认)时,则适用其他规则。
此时,使用 1 像素宽的画笔渲染时,QRectF 的边界线将渲染在数学矩形边界线的右侧和下方。
当使用 2 像素宽的画笔渲染时,边界线将被数学矩形从中分割。只要画笔宽度设置为偶数像素,情况就是如此;而当使用奇数像素宽度的画笔渲染时,多出的那个像素将像 1 像素宽的情况一样,渲染在数学矩形的右侧和下方。
![]() | ![]() |
| 逻辑表示 | 1像素宽的画笔 |
![]() | ![]() |
| 2 像素宽的画笔 | 3像素宽的画笔 |
坐标
QRectF 类提供了一组函数,这些函数可返回各种矩形坐标,并支持对这些坐标进行操作。QRectF 还提供了用于相对于各种坐标移动矩形的函数。
例如:bottom()、setBottom() 和moveBottom() 函数:bottom() 返回矩形底边的 y 坐标,setBottom() 将矩形的底部边缘设置为给定的 y 坐标(这可能会改变高度,但绝不会改变矩形的顶部边缘),而moveBottom() 则将整个矩形沿垂直方向移动,同时保持矩形的底部边缘位于给定的 y 坐标处且其尺寸不变。

此外,还可以使用adjust()函数对该矩形的坐标添加偏移量,以及使用adjusted()函数根据对原始矩形的调整获取一个新矩形。如果宽度和高度中的任一值为负,请使用normalized()函数来获取一个角点位置互换的矩形。
此外,QRectF 还提供了getCoords() 函数,用于提取矩形左上角和右下角的位置;以及getRect() 函数,用于提取矩形的左上角、宽度和高度。使用setCoords() 和setRect() 函数可一次性操作矩形的坐标和尺寸。
成员函数文档
[constexpr noexcept] QRectF::QRectF()
构建一个空矩形。
另请参阅 isNull()。
[constexpr noexcept] QRectF::QRectF(const QRect &rectangle)
根据给定的QRect rectangle 创建一个 QRectF 矩形。
注意:此 函数与QRect::toRectF()一样,保留rectangle 的size()属性,而非其bottomRight()属性。
另请参阅 toRect() 和QRect::toRectF()。
[constexpr noexcept] QRectF::QRectF(const QPointF &topLeft, const QPointF &bottomRight)
根据给定的topLeft 和bottomRight 构建一个矩形。
另请参阅 setTopLeft() 和setBottomRight()。
[constexpr noexcept] QRectF::QRectF(const QPointF &topLeft, const QSizeF &size)
根据给定的topLeft 角和size ,构造一个矩形。
另请参阅 setTopLeft() 和setSize()。
[constexpr noexcept] QRectF::QRectF(qreal x, qreal y, qreal width, qreal height)
构造一个矩形,其左上角坐标为 (x,y),边长分别为给定的width 和height 。所有参数必须是有限的。
另请参阅 setRect()。
[constexpr noexcept] void QRectF::adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
分别将dx1 、dy1 、dx2 和dy2 添加到矩形的现有坐标中。所有参数必须为有限值。
[constexpr noexcept] QRectF QRectF::adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const
返回一个新的矩形,该矩形的坐标在现有坐标基础上分别增加了dx1 、dy1 、dx2 和dy2 。所有参数必须为有限值。
另请参阅 adjust()。
[constexpr noexcept] qreal QRectF::bottom() const
返回矩形底边的 y 坐标。
另请参阅 setBottom()、bottomLeft() 和bottomRight()。
[constexpr noexcept] QPointF QRectF::bottomLeft() const
返回矩形左下角的位置。
另请参阅 setBottomLeft()、bottom() 和left()。
[constexpr noexcept] QPointF QRectF::bottomRight() const
返回矩形右下角的位置。
另请参阅 setBottomRight()、bottom() 和right()。
[constexpr noexcept] QPointF QRectF::center() const
返回矩形的中心点。
另请参阅 moveCenter()。
[noexcept] bool QRectF::contains(const QPointF &point) const
如果给定的point 位于矩形内部或位于矩形边界上,则返回true ;否则返回false 。
另请参阅 intersects()。
[noexcept] bool QRectF::contains(const QRectF &rectangle) const
如果给定的rectangle 位于该矩形内部,则返回true ;否则返回false 。
这是一个重载函数。
[noexcept] bool QRectF::contains(qreal x, qreal y) const
如果点 (x,y) 位于矩形内部或其边界上,则返回true ;否则返回false 。
这是一个重载函数。
[static noexcept] QRectF QRectF::fromCGRect(CGRect rect)
根据 CGRectrect 创建一个QRectF 。
另请参阅 toCGRect()。
[static, since 6.5] QRectF QRectF::fromDOMRect(emscripten::val domRect)
将 DOMRect(https://www.w3.org/TR/geometry-1/)domRect 转换为QRectF 。如果提供的参数不是 DOMRect,则行为未定义。
该函数在 Qt 6.5 中引入。
另请参阅 toDOMRect()。
[constexpr] void QRectF::getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const
将矩形左上角的位置提取到 *x1 和 *y1 ,将右下角的位置提取到 *x2 和 *y2 。
[constexpr] void QRectF::getRect(qreal *x, qreal *y, qreal *width, qreal *height) const
将矩形左上角的位置提取到 *x 和 *y ,将其尺寸提取到 *width 和 *height 。
[constexpr noexcept] qreal QRectF::height() const
返回矩形的高度。
另请参阅 setHeight()、width() 和size()。
[noexcept] QRectF QRectF::intersected(const QRectF &rectangle) const
返回该矩形与给定的rectangle 的交集。请注意,r.intersected(s) 等同于r & s 。

另请参阅 intersects()、united( ) 和operator&=( )。
[noexcept] bool QRectF::intersects(const QRectF &rectangle) const
如果该矩形与给定的rectangle 相交(即它们之间存在非空的重叠区域),则返回true ;否则返回false 。
可通过intersected()函数获取交集矩形。
另请参阅 contains()。
[constexpr noexcept] bool QRectF::isEmpty() const
如果矩形为空,则返回true ;否则返回false 。
空矩形的width() <= 0 或height() <= 0。空矩形无效(即 isEmpty() == !isValid())。
使用normalized() 函数可获取一个四角点位置互换的矩形。
另请参阅 isNull()、isValid() 和normalized()。
[constexpr noexcept] bool QRectF::isNull() const
如果该矩形为空矩形,则返回true ;否则返回false 。
空矩形的宽度和高度均设置为 0。空矩形也是空的,因此无效。
[constexpr noexcept] bool QRectF::isValid() const
如果矩形有效,则返回true ;否则返回false 。
一个有效的矩形满足width() > 0 且height() > 0。请注意,对于无效的矩形,交集等非平凡操作未被定义。有效的矩形不为空(即 isValid() == !isEmpty())。
另请参阅 isNull()、isEmpty() 和normalized()。
[constexpr noexcept] qreal QRectF::left() const
返回矩形左边缘的 x 坐标。等同于x()。
另请参阅 setLeft()、topLeft() 和bottomLeft()。
[constexpr noexcept] QRectF QRectF::marginsAdded(const QMarginsF &margins) const
返回一个通过margins 缩放后的矩形。
另请参阅 operator+=()、marginsRemoved() 和operator-=()。
[constexpr noexcept] QRectF QRectF::marginsRemoved(const QMarginsF &margins) const
从矩形中移除margins ,使其缩小。
另请参阅 marginsAdded()、operator+=() 和operator-=()。
[constexpr noexcept] void QRectF::moveBottom(qreal y)
将矩形沿垂直方向移动,同时保持矩形的下边缘位于给定的有限y 坐标处。矩形的大小保持不变。
另请参阅 bottom()、setBottom() 和moveTop()。
[constexpr noexcept] void QRectF::moveBottomLeft(const QPointF &position)
将矩形移动,使其左下角位于给定的坐标position 处。矩形的大小保持不变。
另请参阅 setBottomLeft()、moveBottom() 和moveLeft()。
[constexpr noexcept] void QRectF::moveBottomRight(const QPointF &position)
将矩形移动,使其右下角位于指定的坐标position 处。矩形的大小保持不变。
另请参阅 setBottomRight()、moveBottom() 和moveRight()。
[constexpr noexcept] void QRectF::moveCenter(const QPointF &position)
将矩形移动,使其中心点位于给定的坐标position 处。矩形的大小保持不变。
另请参阅 center()。
[constexpr noexcept] void QRectF::moveLeft(qreal x)
将矩形水平移动,同时保持矩形左边缘位于给定的有限x 坐标处。矩形的大小保持不变。
另请参阅 left()、setLeft() 和moveRight()。
[constexpr noexcept] void QRectF::moveRight(qreal x)
将矩形水平移动,使其右边缘保持在给定的有限x 坐标处。矩形的大小保持不变。
另请参阅 right()、setRight() 和moveLeft()。
[constexpr noexcept] void QRectF::moveTo(qreal x, qreal y)
将矩形移动,同时保持其左上角位于给定位置(x ,y )。矩形的大小保持不变。这两个参数必须均为有限值。
另请参阅 translate() 和moveTopLeft()。
[constexpr noexcept] void QRectF::moveTo(const QPointF &position)
将矩形移动,使其左上角位于给定的position 处。
这是一个重载函数。
[constexpr noexcept] void QRectF::moveTop(qreal y)
将矩形沿垂直方向移动,使矩形的上边位于给定的有限坐标y 处。矩形的大小保持不变。
另请参阅 top()、setTop() 以及moveBottom()。
[constexpr noexcept] void QRectF::moveTopLeft(const QPointF &position)
将矩形移动,使其左上角位于给定的position 处。矩形的大小保持不变。
另请参阅 setTopLeft()、moveTop() 和moveLeft()。
[constexpr noexcept] void QRectF::moveTopRight(const QPointF &position)
将矩形移动,使其右上角位于给定的position 处。矩形的大小保持不变。
另请参阅 setTopRight()、moveTop() 和moveRight()。
[noexcept] QRectF QRectF::normalized() const
返回一个归一化矩形;即,一个宽度和高度均为非负数的矩形。
如果 `width()` < 0,该函数会交换左右两角的位置;如果 `height()` < 0,则交换上下两角的位置。
[constexpr noexcept] qreal QRectF::right() const
返回矩形右边的 x 坐标。
另请参阅 setRight()、topRight(),以及bottomRight()。
[constexpr noexcept] void QRectF::setBottom(qreal y)
将矩形的下边缘设置为给定的有限坐标y 。可能会改变高度,但绝不会改变矩形的上边缘。
另请参阅 bottom() 和moveBottom()。
[constexpr noexcept] void QRectF::setBottomLeft(const QPointF &position)
将矩形的左下角设置为给定的position 。可能会改变大小,但绝不会改变矩形的右上角。
另请参阅 bottomLeft() 和moveBottomLeft()。
[constexpr noexcept] void QRectF::setBottomRight(const QPointF &position)
将矩形的右下角设置为给定的position 。可能会改变大小,但绝不会改变矩形的左上角。
另请参阅 bottomRight() 和moveBottomRight()。
[constexpr noexcept] void QRectF::setCoords(qreal x1, qreal y1, qreal x2, qreal y2)
将矩形左上角的坐标设置为 (x1,y1),将其右下角的坐标设置为 (x2,y2)。所有参数必须为有限值。
[constexpr noexcept] void QRectF::setHeight(qreal height)
将矩形的高度设置为给定的有限值height 。底部边会发生变化,但顶部边保持不变。
[constexpr noexcept] void QRectF::setLeft(qreal x)
将矩形的左边缘设置为给定的有限x 坐标。可能会改变宽度,但绝不会改变矩形的右边缘。
等同于setX()。
[constexpr noexcept] void QRectF::setRect(qreal x, qreal y, qreal width, qreal height)
将矩形左上角的坐标设置为 (x,y),并将矩形大小设置为给定的width 和height 。所有参数必须为有限值。
[constexpr noexcept] void QRectF::setRight(qreal x)
将矩形的右边缘设置为给定的有限坐标x 。可能会改变宽度,但绝不会改变矩形的左边缘。
[constexpr noexcept] void QRectF::setSize(const QSizeF &size)
将矩形的大小设置为给定的有限值size 。左上角位置不变。
另请参阅 size()、setWidth() 和setHeight()。
[constexpr noexcept] void QRectF::setTop(qreal y)
将矩形的顶边设置为给定的有限y 坐标。可能会改变高度,但绝不会改变矩形的底边。
等同于setY()。
[constexpr noexcept] void QRectF::setTopLeft(const QPointF &position)
将矩形的左上角设置为给定的position 。可能会改变尺寸,但绝不会改变矩形的右下角。
另请参阅 topLeft() 和moveTopLeft()。
[constexpr noexcept] void QRectF::setTopRight(const QPointF &position)
将矩形的右上角设置为给定的position 。可能会改变矩形的大小,但绝不会改变其左下角的位置。
另请参阅 topRight() 和moveTopRight()。
[constexpr noexcept] void QRectF::setWidth(qreal width)
将矩形的宽度设置为给定的有限值width 。右边缘会发生变化,但左边缘保持不变。
[constexpr noexcept] void QRectF::setX(qreal x)
将矩形的左边缘设置为给定的有限x 坐标。可能会改变宽度,但绝不会改变矩形的右边缘。
等同于setLeft()。
另请参阅 x()、setY() 和setTopLeft()。
[constexpr noexcept] void QRectF::setY(qreal y)
将矩形的顶边设置为给定的有限y 坐标。可能会改变高度,但绝不会改变矩形的底边。
等同于setTop()。
另请参阅 y()、setX() 以及setTopLeft()。
[constexpr noexcept] QSizeF QRectF::size() const
返回矩形的大小。
另请参阅 setSize()、width() 和height()。
[noexcept] QRect QRectF::toAlignedRect() const
根据该矩形的值,返回一个QRect ,该矩形是能够完全包含该矩形且尺寸尽可能小的整数矩形。
另请参阅 toRect()。
[noexcept] CGRect QRectF::toCGRect() const
根据QRectF 创建一个CGRect。
另请参阅 fromCGRect()。
[since 6.5] emscripten::val QRectF::toDOMRect() const
将此对象转换为 DOMRect(https://www.w3.org/TR/geometry-1/)。
该函数在 Qt 6.5 中引入。
另请参阅 fromDOMRect()。
[constexpr noexcept] QRect QRectF::toRect() const
根据该矩形的值返回一个 `QRect ` 对象。请注意,返回的矩形中的坐标会四舍五入到最接近的整数。
另请参阅 QRectF()、toAlignedRect() 和QRect::toRectF()。
[constexpr noexcept] qreal QRectF::top() const
返回矩形顶边上的y坐标。等同于y()。
另请参阅 setTop()、topLeft() 和topRight()。
[constexpr noexcept] QPointF QRectF::topLeft() const
返回矩形左上角的位置。
另请参阅 setTopLeft()、top() 和left()。
[constexpr noexcept] QPointF QRectF::topRight() const
返回矩形右上角的位置。
另请参阅 setTopRight()、top() 和right()。
[constexpr noexcept] void QRectF::translate(qreal dx, qreal dy)
将矩形沿 x 轴移动dx ,沿 y 轴移动dy ,以当前位置为基准。正值表示将矩形向右下方移动。这两个参数必须为有限值。
另请参阅 moveTopLeft()、moveTo() 和translated()。
[constexpr noexcept] void QRectF::translate(const QPointF &offset)
将矩形offset 、x()沿x轴移动,并沿y轴offset 、y()移动,以当前位置为基准。
这是一个重载函数。
[constexpr noexcept] QRectF QRectF::translated(qreal dx, qreal dy) const
返回一个矩形的副本,该矩形相对于当前位置沿 x 轴平移dx ,沿 y 轴平移dy 。正值会将矩形向右和向下移动。这两个参数必须是有限值。
另请参阅 translate()。
[constexpr noexcept] QRectF QRectF::translated(const QPointF &offset) const
返回一个矩形的副本,该矩形相对于当前位置沿 x 轴平移了offset 。x(),沿 y 轴平移了offset 。y()。
这是一个重载函数。
[constexpr noexcept] QRectF QRectF::transposed() const
返回一个矩形的副本,其宽度和高度已被互换:
QRectF r = {1.5, 5.1, 4.2, 2.4};
r = r.transposed(); // r == {1.5, 5.1, 2.4, 4.2}另请参阅 ` QSizeF::transposed()`。
[noexcept] QRectF QRectF::united(const QRectF &rectangle) const
返回该矩形与给定的rectangle 构成的边界矩形。

另请参阅 intersected()。
[constexpr noexcept] qreal QRectF::width() const
返回矩形的宽度。
另请参阅 setWidth()、height() 和size()。
[constexpr noexcept] qreal QRectF::x() const
返回矩形左边缘的 x 坐标。等同于left()。
[constexpr noexcept] qreal QRectF::y() const
返回矩形顶边上的 y 坐标。等同于top()。
[noexcept] QRectF QRectF::operator&(const QRectF &rectangle) const
返回该矩形与给定的rectangle 的交集。若无交集,则返回一个空矩形。
另请参阅 operator&=() 和intersected()。
[noexcept] QRectF &QRectF::operator&=(const QRectF &rectangle)
计算该矩形与给定rectangle 的交集。
另请参阅 intersected() 和operator&()。
[constexpr noexcept] QRectF &QRectF::operator+=(const QMarginsF &margins)
将margins 添加到矩形中,并使矩形变大。
另请参阅 marginsAdded()、marginsRemoved() 以及operator-=()。
[constexpr noexcept] QRectF &QRectF::operator-=(const QMarginsF &margins)
返回一个经过margins 缩放后的矩形。
另请参阅 marginsRemoved()、operator+=() 和marginsAdded()。
[noexcept] QRectF QRectF::operator|(const QRectF &rectangle) const
返回该矩形与给定rectangle 的包围矩形。
另请参阅 united() 和operator|=()。
[noexcept] QRectF &QRectF::operator|=(const QRectF &rectangle)
将此矩形与给定的rectangle 合并。
相关的非成员
[constexpr noexcept, since 6.8] bool qFuzzyCompare(const QRectF &lhs, const QRectF &rhs)
如果矩形lhs 与矩形rhs 近似相等,则返回true ;否则返回false 。
该函数在 Qt 6.8 中引入。
[constexpr noexcept, since 6.8] bool qFuzzyIsNull(const QRectF &rect)
如果矩形rect 的宽度和高度均近似于零,则返回true ;否则返回false 。
该函数在 Qt 6.8 中引入。
[constexpr noexcept] bool operator!=(const QRectF &lhs, const QRectF &rhs)
如果矩形lhs 和rhs 之间存在足够大的差异,则返回true ;否则返回false 。
警告:此 函数不检查严格不等关系;而是使用模糊比较来比较矩形的坐标。
[constexpr noexcept] QRectF operator+(const QRectF &lhs, const QMarginsF &rhs)
返回一个lhs 矩形,该矩形已根据rhs 的边距进行扩展。
[constexpr noexcept] QRectF operator+(const QMarginsF &lhs, const QRectF &rhs)
返回一个通过rhs 边距进行扩大的lhs 矩形。
这是一个重载函数。
[constexpr noexcept] QRectF operator-(const QRectF &lhs, const QMarginsF &rhs)
返回经过rhs 边距缩减后的lhs 矩形。
QDataStream &operator<<(QDataStream &stream, const QRectF &rectangle)
将rectangle 写入stream ,并返回该流的引用。
另请参阅 《Qt 数据类型的序列化》。
[constexpr noexcept] bool operator==(const QRectF &lhs, const QRectF &rhs)
如果矩形lhs 和rhs 近似相等,则返回true ;否则返回false 。
警告:此 函数不检查严格相等性;而是使用模糊比较来比较矩形的坐标。
另请参阅 qFuzzyCompare 。
QDataStream &operator>>(QDataStream &stream, QRectF &rectangle)
从stream 中读取rectangle ,并返回该流的引用。
另请参阅 《Qt 数据类型的序列化》。
© 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.



