本页内容

QRect Class

QRect 类使用整数精度在平面上定义一个矩形。更多内容...

头文件: #include <QRect>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

注意:该类中的所有函数均为可重入函数。

QRect 比较

类别可比较类型
相等QRect
相等性QRectF.

公共函数

QRect()
QRect(const QPoint &topLeft, const QPoint &bottomRight)
QRect(const QPoint &topLeft, const QSize &size)
QRect(int x, int y, int width, int height)
void adjust(int dx1, int dy1, int dx2, int dy2)
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const
int bottom() const
QPoint bottomLeft() const
QPoint bottomRight() const
QPoint center() const
bool contains(const QPoint &point, bool proper = false) const
bool contains(const QRect &rectangle, bool proper = false) const
bool contains(int x, int y) const
bool contains(int x, int y, bool proper) const
void getCoords(int *x1, int *y1, int *x2, int *y2) const
void getRect(int *x, int *y, int *width, int *height) const
int height() const
QRect intersected(const QRect &rectangle) const
bool intersects(const QRect &rectangle) const
bool isEmpty() const
bool isNull() const
bool isValid() const
int left() const
QRect marginsAdded(const QMargins &margins) const
QRect marginsRemoved(const QMargins &margins) const
void moveBottom(int y)
void moveBottomLeft(const QPoint &position)
void moveBottomRight(const QPoint &position)
void moveCenter(const QPoint &position)
void moveLeft(int x)
void moveRight(int x)
void moveTo(const QPoint &position)
void moveTo(int x, int y)
void moveTop(int y)
void moveTopLeft(const QPoint &position)
void moveTopRight(const QPoint &position)
QRect normalized() const
int right() const
void setBottom(int y)
void setBottomLeft(const QPoint &position)
void setBottomRight(const QPoint &position)
void setCoords(int x1, int y1, int x2, int y2)
void setHeight(int height)
void setLeft(int x)
void setRect(int x, int y, int width, int height)
void setRight(int x)
void setSize(const QSize &size)
void setTop(int y)
void setTopLeft(const QPoint &position)
void setTopRight(const QPoint &position)
void setWidth(int width)
void setX(int x)
void setY(int y)
QSize size() const
CGRect toCGRect() const
(since 6.4) QRectF toRectF() const
int top() const
QPoint topLeft() const
QPoint topRight() const
void translate(int dx, int dy)
void translate(const QPoint &offset)
QRect translated(int dx, int dy) const
QRect translated(const QPoint &offset) const
QRect transposed() const
QRect united(const QRect &rectangle) const
int width() const
int x() const
int y() const
QRect operator&(const QRect &rectangle) const
QRect &operator&=(const QRect &rectangle)
QRect &operator+=(const QMargins &margins)
QRect &operator-=(const QMargins &margins)
QRect operator|(const QRect &rectangle) const
QRect &operator|=(const QRect &rectangle)

静态公共成员

(since 6.0) QRect span(const QPoint &p1, const QPoint &p2)
bool operator!=(const QRect &lhs, const QRect &rhs)
QRect operator+(const QRect &rectangle, const QMargins &margins)
QRect operator+(const QMargins &margins, const QRect &rectangle)
QRect operator-(const QRect &lhs, const QMargins &rhs)
QDataStream &operator<<(QDataStream &stream, const QRect &rectangle)
bool operator==(const QRect &lhs, const QRect &rhs)
QDataStream &operator>>(QDataStream &stream, QRect &rectangle)

详细说明

矩形通常由左上角坐标和尺寸来表示。QRect 的尺寸(宽度和高度)始终等同于构成其渲染基础的数学矩形。

可以通过一组表示左、上、宽和高的整数来构造一个 QRect,也可以通过一个 `QPoint ` 和一个 `QSize` 来构造。以下代码创建了两个相同的矩形。

QRect r1(100, 200, 11, 16);
QRect r2(QPoint(100, 200), QSize(11, 16));

还有第三种构造函数,它使用左上角和右下角坐标创建 QRect,但我们建议您避免使用它。原因在于,出于历史原因,bottom() 和right() 函数返回的值与矩形真正的右下角存在偏差。

QRect 类提供了一组函数,这些函数可返回矩形的各种坐标,并支持对这些坐标进行操作。 QRect 还提供了用于相对于各种坐标移动矩形的函数。此外,还有moveTo() 函数,该函数在保持矩形左上角位于指定坐标不变的情况下移动矩形。另外,translate() 函数会将矩形相对于当前位置移动指定的偏移量,而translated() 函数则返回该矩形经平移后的副本。

size() 函数将矩形的尺寸作为QSize 返回。也可以通过width() 和height() 函数分别获取这些尺寸。要操作尺寸,请使用setSize()、setWidth() 或setHeight() 函数。此外,还可以通过调用设置矩形坐标的函数(例如setBottom() 或setRight())来更改尺寸。

contains() 函数用于判断给定点是否位于矩形内部,而intersects() 函数若该矩形与给定矩形相交,则返回true 。QRect 类还提供了intersected() 函数,该函数返回相交矩形;以及united() 函数,该函数返回同时包含给定矩形和当前矩形的矩形:

当left() >right() 或top() >bottom() 时,isEmpty() 函数返回true 。请注意,空矩形是不合法的:当left() <=right()且 top() <=bottom() 时,isValid() 函数返回true 。另一方面,空矩形(isNull() == true)的宽度和高度均设为 0。

请注意,由于 QRect 和QRectF 的定义方式,空的 QRect 实际上与QRectF 的定义方式基本相同。

最后,QRect 对象既可以进行流式传输,也可以进行比较。

渲染

使用anti-aliased 绘图器时,QRect 的边界线将在数学矩形边界线的两侧对称地渲染。但使用锯齿绘图器(默认)时,则适用其他规则。

此时,使用 1 像素宽的画笔进行渲染时,QRect 的边界线将渲染在数学矩形边界线的右侧和下方。

当使用2像素宽的画笔渲染时,边界线将被数学矩形从中分割。只要画笔宽度设置为偶数像素,情况便是如此;而使用奇数像素宽度的画笔渲染时,多出的那个像素将像1像素宽的情况一样,渲染在数学矩形的右侧和下方。

显示宽度和高度尺寸的矩形用1像素粗细的笔画出的矩形,显示其角坐标
逻辑表示1像素宽画笔
显示角坐标的、笔宽为两个像素的矩形显示角坐标的、笔宽为3像素的矩形
2 像素宽的画笔3像素宽的画笔

坐标

QRect 类提供了一组函数,这些函数可返回各种矩形坐标并支持对这些坐标进行操作。QRect 还提供了用于相对于各种坐标移动矩形的函数。

例如,以下是left()、setLeft() 和moveLeft() 函数的示例:left() 返回矩形左边缘的 x 坐标,setLeft() 将矩形的左边缘设置为给定的 x 坐标(这可能会改变宽度,但绝不会改变矩形的右边缘),而moveLeft() 则将整个矩形水平移动,同时保持矩形的左边缘位于给定的 x 坐标处且其尺寸不变。

一个矩形的示意图,展示了 QRect 类中用于表示位置的方法:x()、y()、center()、顶点(topLeft()、topRight()、bottomLeft()、bottomRight())以及边(top()、bottom()、left()、right())。

请注意,由于历史原因,bottom() 和right() 函数返回的值与矩形真正的右下角存在偏差:right() 函数返回 left() +width() - 1,而bottom() 函数返回top() +height() - 1。bottomRight() 便捷函数返回的点也是如此。此外,topRight() 和bottomLeft() 函数分别返回的 x 和 y 坐标,与真实右边缘和底边缘的偏差相同。

我们建议您使用x() +width() 以及y() +height() 来查找真正的右下角,并避免使用right() 和bottom()。另一种解决方案是使用QRectF :QRectF 类使用浮点精度定义平面上的矩形坐标,而QRectF::right() 和QRectF::bottom() 函数确实会返回右侧和底部的坐标。

此外,还可以通过adjust()函数对该矩形的坐标添加偏移量,也可以通过adjusted()函数根据对原始矩形的调整来获取一个新的矩形。如果宽度和高度中的任一值为负,请使用normalized()函数来获取一个角点位置互换的矩形。

此外,QRect 还提供了getCoords() 函数,用于提取矩形左上角和右下角的位置;以及getRect() 函数,用于提取矩形的左上角、宽度和高度。使用setCoords() 和setRect() 函数可一次性操作矩形的坐标和尺寸。

限制

QRect 的取值范围受限于int 类型的最小值和最大值。对 QRect 进行的操作若可能导致值超出此范围,将引发未定义行为。

另请参阅 QRectF 和QRegion 。

成员函数文档

[constexpr noexcept] QRect::QRect()

构建一个空矩形。

另请参阅 isNull()。

[constexpr noexcept] QRect::QRect(const QPoint &topLeft, const QPoint &bottomRight)

根据给定的topLeft 和bottomRight 两个角(均包含在内)构造一个矩形。

如果bottomRight 位于topLeft 上方且左侧,则定义的矩形将不包含这两个顶点。

注意:为确保 无论相对顺序如何,两个点均被包含在内,请使用span()。

另请参阅 setTopLeft()、setBottomRight() 和span()。

[constexpr noexcept] QRect::QRect(const QPoint &topLeft, const QSize &size)

根据给定的topLeft 角和给定的size 绘制一个矩形。

另请参阅 setTopLeft() 和setSize()。

[constexpr noexcept] QRect::QRect(int x, int y, int width, int height)

构建一个矩形,其左上角坐标为 (x,y),并使用给定的width 和height 。

另请参阅 setRect()。

[constexpr noexcept] void QRect::adjust(int dx1, int dy1, int dx2, int dy2)

分别将dx1 、dy1 、dx2 和dy2 添加到矩形现有的坐标中。

另请参阅 adjusted() 和setRect()。

[constexpr noexcept] QRect QRect::adjusted(int dx1, int dy1, int dx2, int dy2) const

返回一个新的矩形,该矩形在现有坐标基础上分别添加了dx1 、dy1 、dx2 和dy2 。

另请参阅 adjust()。

[constexpr noexcept] int QRect::bottom() const

返回矩形底边的 y 坐标。

请注意,出于历史原因,该函数返回的值是 `top()` + `height()` - 1;若要获取真实的 y 坐标,请使用 `y()` + `height()`。

另请参阅 setBottom()、bottomLeft() 和bottomRight()。

[constexpr noexcept] QPoint QRect::bottomLeft() const

返回矩形左下角的位置。请注意,出于历史原因,该函数返回QPoint (left(),top() +height() - 1)。

另请参阅 setBottomLeft()、bottom() 和left()。

[constexpr noexcept] QPoint QRect::bottomRight() const

返回矩形右下角的位置。

请注意,出于历史原因,该函数返回QPoint (left() +width() - 1,top() +height() - 1)。

另请参阅 setBottomRight()、bottom() 和right()。

[constexpr noexcept] QPoint QRect::center() const

返回矩形的中心点。

另请参阅 moveCenter()。

[noexcept] bool QRect::contains(const QPoint &point, bool proper = false) const

如果给定的point 位于矩形内部或边上,则返回true ;否则返回false 。如果proper 为真,则该函数仅在给定的point 位于矩形内部(即不在边上)时才返回true 。

另请参阅 intersects()。

[noexcept] bool QRect::contains(const QRect &rectangle, bool proper = false) const

如果给定的rectangle 位于该矩形内部,则返回true ;否则返回false 。如果proper 为真,则只有当rectangle 完全位于该矩形内部(且不在边界上)时,该函数才返回true 。

这是一个重载函数。

[noexcept] bool QRect::contains(int x, int y) const

如果点 (x,y) 位于该矩形内部,则返回true ;否则返回false 。

这是一个重载函数。

[noexcept] bool QRect::contains(int x, int y, bool proper) const

如果点 (x,y) 位于矩形内部或边上,则返回true ;否则返回false 。如果proper 为真,则该函数仅在点完全位于矩形内部(而非位于边上)时才返回true 。

这是一个重载函数。

[constexpr] void QRect::getCoords(int *x1, int *y1, int *x2, int *y2) const

将矩形左上角的位置提取到 *x1 和 *y1 ,将右下角的位置提取到 *x2 和 *y2 。

另请参阅 setCoords() 和getRect()。

[constexpr] void QRect::getRect(int *x, int *y, int *width, int *height) const

将矩形左上角的位置提取到 *x 和 *y ,将其尺寸提取到 *width 和 *height 。

另请参阅 setRect() 和getCoords()。

[constexpr noexcept] int QRect::height() const

返回矩形的高度。

另请参阅 setHeight()、width() 和size()。

[noexcept] QRect QRect::intersected(const QRect &rectangle) const

返回该矩形与给定rectangle 的交集。请注意,r.intersected(s) 等同于r & s 。

该图展示了两个矩形 r 和 s 的交集,并突出了重叠区域。图中还说明了如何通过 r.intersect(s).width 和 r.intersect(s).height() 来确定突出显示区域的宽度和高度。

另请参阅 intersects()、united() 和operator&=()。

[noexcept] bool QRect::intersects(const QRect &rectangle) const

如果该矩形与给定的rectangle 相交(即至少有一个像素同时位于两个矩形内),则返回true ;否则返回false 。

可通过intersected() 函数获取交集矩形。

另请参阅 contains()。

[constexpr noexcept] bool QRect::isEmpty() const

如果矩形为空,则返回true ;否则返回false 。

空矩形的left() >right() 或top() >bottom()。空矩形无效(即 isEmpty() == !isValid())。

使用normalized() 函数可获取一个四角位置互换的矩形。

另请参阅 isNull()、isValid() 和normalized()。

[constexpr noexcept] bool QRect::isNull() const

如果该矩形为空矩形,则返回true ;否则返回false 。

空矩形的宽度和高度均设置为 0(即right() ==left() - 1 且bottom() ==top() - 1)。空矩形也是空的,因此无效。

另请参阅 isEmpty() 和isValid()。

[constexpr noexcept] bool QRect::isValid() const

如果矩形有效,则返回true ;否则返回false 。

一个有效的矩形满足left() <=right() 且top() <=bottom()。请注意,对于无效的矩形,交集等非平凡操作未被定义。有效的矩形不为空(即 isValid() == !isEmpty())。

另请参阅 isNull()、isEmpty() 和normalized()。

[constexpr noexcept] int QRect::left() const

返回矩形左边缘的 x 坐标。等同于x()。

另请参见 setLeft()、topLeft() 和bottomLeft()。

[constexpr noexcept] QRect QRect::marginsAdded(const QMargins &margins) const

返回一个通过margins 扩展的矩形。

另请参阅 operator+=()、marginsRemoved() 和operator-=()。

[constexpr noexcept] QRect QRect::marginsRemoved(const QMargins &margins) const

从矩形中移除margins ,使其缩小。

另请参阅 marginsAdded()、operator+=() 和operator-=()。

[constexpr noexcept] void QRect::moveBottom(int y)

将矩形沿垂直方向移动,同时保持矩形底边位于给定的y 坐标处。矩形的大小保持不变。

另请参阅 bottom()、setBottom() 和moveTop()。

[constexpr noexcept] void QRect::moveBottomLeft(const QPoint &position)

将矩形移动,使其左下角位于给定的坐标position 处。矩形的尺寸保持不变。

另请参阅 setBottomLeft()、moveBottom() 和moveLeft()。

[constexpr noexcept] void QRect::moveBottomRight(const QPoint &position)

将矩形移动,使其右下角位于给定的position 处。矩形的大小保持不变。

另请参阅 setBottomRight()、moveRight() 和moveBottom()。

[constexpr noexcept] void QRect::moveCenter(const QPoint &position)

将矩形移动,使其中心点位于给定的position 处。矩形的大小保持不变。

另请参阅 center()。

[constexpr noexcept] void QRect::moveLeft(int x)

将矩形水平移动,同时保持矩形左边缘位于给定的x 坐标处。矩形的大小保持不变。

另请参阅 left()、setLeft() 和moveRight()。

[constexpr noexcept] void QRect::moveRight(int x)

将矩形水平移动,使其右边缘位于给定的x 坐标处。矩形的大小保持不变。

另请参阅 right()、setRight() 和moveLeft()。

[constexpr noexcept] void QRect::moveTo(const QPoint &position)

将矩形移动,使其左上角位于给定的position 处。

[constexpr noexcept] void QRect::moveTo(int x, int y)

移动矩形,同时保持其左上角位于指定位置(x 、y )。矩形的大小保持不变。

另请参阅 translate() 和moveTopLeft()。

[constexpr noexcept] void QRect::moveTop(int y)

将矩形沿垂直方向移动,同时保持矩形顶边位于给定的y 坐标处。矩形的大小保持不变。

另请参阅 top()、setTop() 和moveBottom()。

[constexpr noexcept] void QRect::moveTopLeft(const QPoint &position)

将矩形移动,使其左上角保持在给定的position 位置。矩形的大小保持不变。

另请参阅 setTopLeft()、moveTop() 以及moveLeft()。

[constexpr noexcept] void QRect::moveTopRight(const QPoint &position)

将矩形移动,使其右上角位于给定的position 处。矩形的大小保持不变。

另请参阅 setTopRight()、moveTop() 和moveRight()。

[noexcept] QRect QRect::normalized() const

返回一个归一化矩形;即,宽度和高度均为非负数的矩形。

如果 `width()` < 0,则该函数会交换左右角的位置;如果 `height()` < 0,则会交换上下角的位置。同时,这些角的定义也会从“不包含”变为“包含”。

另请参阅 isValid() 和isEmpty()。

返回矩形右边的 x 坐标。

请注意,出于历史原因,该函数返回的值是left() +width() - 1;若要获取真正的 x 坐标,请使用x() +width()。

另请参阅 setRight()、topRight() 和bottomRight()。

[constexpr noexcept] void QRect::setBottom(int y)

将矩形的底边设置为给定的y 坐标。可能会改变高度,但绝不会改变矩形的顶边。

另请参阅 bottom() 和moveBottom()。

[constexpr noexcept] void QRect::setBottomLeft(const QPoint &position)

将矩形的左下角设置为给定的position 。可能会改变大小,但绝不会改变矩形的右上角。

另请参阅 bottomLeft() 和moveBottomLeft()。

[constexpr noexcept] void QRect::setBottomRight(const QPoint &position)

将矩形的右下角设置为给定的position 。可能会改变尺寸,但绝不会改变矩形的左上角。

另请参阅 bottomRight() 和moveBottomRight()。

[constexpr noexcept] void QRect::setCoords(int x1, int y1, int x2, int y2)

将矩形左上角的坐标设置为 (x1,y1),将其右下角的坐标设置为 (x2,y2)。

另请参阅 getCoords() 和setRect()。

[constexpr noexcept] void QRect::setHeight(int height)

将矩形的高度设置为给定的height 。底部边会发生变化,但顶部边保持不变。

另请参阅 height() 和setSize()。

[constexpr noexcept] void QRect::setLeft(int x)

将矩形的左边缘设置为给定的x 坐标。可能会改变宽度,但绝不会改变矩形的右边缘。

等同于setX()。

另请参阅 left() 和moveLeft()。

[constexpr noexcept] void QRect::setRect(int x, int y, int width, int height)

将矩形左上角的坐标设置为 (x,y),并将矩形大小设置为给定的width 和height 。

另请参阅 getRect() 和setCoords()。

[constexpr noexcept] void QRect::setRight(int x)

将矩形的右边缘设置为给定的x 坐标。可能会改变宽度,但绝不会改变矩形的左边缘。

另请参阅 right() 和moveRight()。

[constexpr noexcept] void QRect::setSize(const QSize &size)

将矩形的大小设置为给定的size 。左上角位置保持不变。

另请参阅 size()、setWidth() 以及setHeight()。

[constexpr noexcept] void QRect::setTop(int y)

将矩形的顶边设置为给定的y 坐标。可能会改变高度,但绝不会改变矩形的底边。

等同于setY()。

另请参阅 top() 和moveTop()。

[constexpr noexcept] void QRect::setTopLeft(const QPoint &position)

将矩形的左上角设置为给定的position 。可能会改变大小,但绝不会改变矩形的右下角。

另请参阅 topLeft() 和moveTopLeft()。

[constexpr noexcept] void QRect::setTopRight(const QPoint &position)

将矩形的右上角设置为给定的position 。尺寸可能会发生变化,但矩形的左下角绝不会改变。

另请参阅 topRight() 和moveTopRight()。

[constexpr noexcept] void QRect::setWidth(int width)

将矩形的宽度设置为给定的width 。右边缘会发生变化,但左边缘保持不变。

另请参阅 width() 和setSize()。

[constexpr noexcept] void QRect::setX(int x)

将矩形的左边缘设置为给定的x 坐标。可能会改变宽度,但绝不会改变矩形的右边缘。

等同于setLeft()。

另请参阅 x()、setY() 和setTopLeft()。

[constexpr noexcept] void QRect::setY(int y)

将矩形的顶边设置为给定的y 坐标。可能会改变高度,但绝不会改变矩形的底边。

等同于setTop()。

另请参阅 y()、setX() 和setTopLeft()。

[constexpr noexcept] QSize QRect::size() const

返回矩形的大小。

另请参阅 setSize()、width(),以及height()。

[static constexpr noexcept, since 6.0] QRect QRect::span(const QPoint &p1, const QPoint &p2)

返回一个连接两个点p1 和p2 的矩形,该矩形包含这两个点以及两者之间的所有区域。

该函数在 Qt 6.0 中引入。

[noexcept] CGRect QRect::toCGRect() const

根据QRect 创建一个CGRect。

另请参阅 QRectF::fromCGRect()。

[constexpr noexcept, since 6.4] QRectF QRect::toRectF() const

将此矩形作为具有浮点精度的矩形返回。

注意:此 函数与QRectF (QRect )构造函数一样,保留矩形的size(),而非其bottomRight()的角点。

该函数于 Qt 6.4 中引入。

另请参阅 QRectF::toRect()。

[constexpr noexcept] int QRect::top() const

返回矩形顶边的中点y坐标。等同于y()。

另请参阅 setTop()、topLeft() 和topRight()。

[constexpr noexcept] QPoint QRect::topLeft() const

返回矩形左上角的位置。

另请参阅 setTopLeft()、top() 和left()。

[constexpr noexcept] QPoint QRect::topRight() const

返回矩形右上角的位置。

请注意,出于历史原因,该函数返回QPoint (left() +width() -1,top())。

另请参阅 setTopRight()、top() 和right()。

[constexpr noexcept] void QRect::translate(int dx, int dy)

将矩形沿 x 轴移动dx ,沿 y 轴移动dy ,以当前位置为基准。正值表示将矩形向右和向下移动。

另请参阅 moveTopLeft()、moveTo() 和translated()。

[constexpr noexcept] void QRect::translate(const QPoint &offset)

将矩形offset 、x()沿x轴移动,并沿y轴移动offset 、y(),移动基准为当前位置。

这是一个重载函数。

[constexpr noexcept] QRect QRect::translated(int dx, int dy) const

返回一个矩形的副本,该矩形相对于当前位置沿 x 轴平移了dx ,沿 y 轴平移了dy 。正值会将矩形向右和向下移动。

另请参阅 translate()。

[constexpr noexcept] QRect QRect::translated(const QPoint &offset) const

返回一个矩形的副本,该矩形相对于当前位置沿 x 轴平移offset ,x(),沿 y 轴平移offset ,y()。

这是一个重载函数。

[constexpr noexcept] QRect QRect::transposed() const

返回一个矩形的副本,该副本的宽度和高度已被互换:

QRect r = {15, 51, 42, 24};
r = r.transposed(); // r == {15, 51, 24, 42}

另请参阅 ` QSize::transposed()`。

[noexcept] QRect QRect::united(const QRect &rectangle) const

返回该矩形与给定的rectangle 的包围矩形。

该图示展示了两个重叠的矩形 r 和 s,以及它们合并后的尺寸,该尺寸通过 r.united(s).width 和 r.united(s).height() 确定。

另请参阅 intersected()。

[constexpr noexcept] int QRect::width() const

返回矩形的宽度。

另请参阅 setWidth()、height() 和size()。

[constexpr noexcept] int QRect::x() const

返回矩形左边缘的x坐标。等同于left()。

另请参阅 setX()、y() 和topLeft()。

[constexpr noexcept] int QRect::y() const

返回矩形顶边上的 y 坐标。等同于top()。

另请参阅 setY()、x() 和topLeft()。

[noexcept] QRect QRect::operator&(const QRect &rectangle) const

返回该矩形与给定rectangle 的交集。若无交集,则返回一个空矩形。

另请参阅 operator&=() 和intersected()。

[noexcept] QRect &QRect::operator&=(const QRect &rectangle)

求该矩形与给定的rectangle 的交集。

另请参阅 intersected() 和operator&()。

[constexpr noexcept] QRect &QRect::operator+=(const QMargins &margins)

将margins 添加到矩形中,并使其扩大。

另请参阅 marginsAdded()、marginsRemoved() 和operator-=()。

[constexpr noexcept] QRect &QRect::operator-=(const QMargins &margins)

返回一个经margins 缩放后的矩形。

另请参阅 marginsRemoved()、operator+=() 和marginsAdded()。

[noexcept] QRect QRect::operator|(const QRect &rectangle) const

返回该矩形与给定rectangle 的包围矩形。

另请参阅 operator|=() 和united()。

[noexcept] QRect &QRect::operator|=(const QRect &rectangle)

将此矩形与给定的rectangle 合并。

另请参阅 united() 和operator|()。

相关的非成员

[constexpr noexcept] bool operator!=(const QRect &lhs, const QRect &rhs)

如果矩形lhs 和rhs 不同,则返回true ;否则返回false 。

[constexpr noexcept] QRect operator+(const QRect &rectangle, const QMargins &margins)

返回由margins 生成的rectangle 。

[constexpr noexcept] QRect operator+(const QMargins &margins, const QRect &rectangle)

返回由margins 生成的rectangle 。

这是一个重载函数。

[constexpr noexcept] QRect operator-(const QRect &lhs, const QMargins &rhs)

返回经过rhs 边距缩小的lhs 矩形。

QDataStream &operator<<(QDataStream &stream, const QRect &rectangle)

将给定的rectangle 写入给定的stream ,并返回该流的引用。

另请参阅 《Qt 数据类型的序列化》。

[constexpr noexcept] bool operator==(const QRect &lhs, const QRect &rhs)

如果矩形lhs 和rhs 相等,则返回true ;否则返回false 。

QDataStream &operator>>(QDataStream &stream, QRect &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.