QtBase  v6.3.1
Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QRect Class Reference

The QRect class defines a rectangle in the plane using integer precision. More...

#include <qrect.h>

Public Member Functions

constexpr QRect () noexcept
 
constexpr QRect (const QPoint &topleft, const QPoint &bottomright) noexcept
 
constexpr QRect (const QPoint &topleft, const QSize &size) noexcept
 
constexpr QRect (int left, int top, int width, int height) noexcept
 
constexpr bool isNull () const noexcept
 
constexpr bool isEmpty () const noexcept
 
constexpr bool isValid () const noexcept
 
constexpr int left () const noexcept
 
constexpr int top () const noexcept
 
constexpr int right () const noexcept
 
constexpr int bottom () const noexcept
 
QRect normalized () const noexcept
 
constexpr int x () const noexcept
 
constexpr int y () const noexcept
 
constexpr void setLeft (int pos) noexcept
 
constexpr void setTop (int pos) noexcept
 
constexpr void setRight (int pos) noexcept
 
constexpr void setBottom (int pos) noexcept
 
constexpr void setX (int x) noexcept
 
constexpr void setY (int y) noexcept
 
constexpr void setTopLeft (const QPoint &p) noexcept
 
constexpr void setBottomRight (const QPoint &p) noexcept
 
constexpr void setTopRight (const QPoint &p) noexcept
 
constexpr void setBottomLeft (const QPoint &p) noexcept
 
constexpr QPoint topLeft () const noexcept
 
constexpr QPoint bottomRight () const noexcept
 
constexpr QPoint topRight () const noexcept
 
constexpr QPoint bottomLeft () const noexcept
 
constexpr QPoint center () const noexcept
 
constexpr void moveLeft (int pos) noexcept
 
constexpr void moveTop (int pos) noexcept
 
constexpr void moveRight (int pos) noexcept
 
constexpr void moveBottom (int pos) noexcept
 
constexpr void moveTopLeft (const QPoint &p) noexcept
 
constexpr void moveBottomRight (const QPoint &p) noexcept
 
constexpr void moveTopRight (const QPoint &p) noexcept
 
constexpr void moveBottomLeft (const QPoint &p) noexcept
 
constexpr void moveCenter (const QPoint &p) noexcept
 
constexpr void translate (int dx, int dy) noexcept
 
constexpr void translate (const QPoint &p) noexcept
 
constexpr QRect translated (int dx, int dy) const noexcept
 
constexpr QRect translated (const QPoint &p) const noexcept
 
constexpr QRect transposed () const noexcept
 
constexpr void moveTo (int x, int t) noexcept
 
constexpr void moveTo (const QPoint &p) noexcept
 
constexpr void setRect (int x, int y, int w, int h) noexcept
 
constexpr void getRect (int *x, int *y, int *w, int *h) const
 
constexpr void setCoords (int x1, int y1, int x2, int y2) noexcept
 
constexpr void getCoords (int *x1, int *y1, int *x2, int *y2) const
 
constexpr void adjust (int x1, int y1, int x2, int y2) noexcept
 
constexpr QRect adjusted (int x1, int y1, int x2, int y2) const noexcept
 
constexpr QSize size () const noexcept
 
constexpr int width () const noexcept
 
constexpr int height () const noexcept
 
constexpr void setWidth (int w) noexcept
 
constexpr void setHeight (int h) noexcept
 
constexpr void setSize (const QSize &s) noexcept
 
QRect operator| (const QRect &r) const noexcept
 
QRect operator& (const QRect &r) const noexcept
 
QRectoperator|= (const QRect &r) noexcept
 
QRectoperator&= (const QRect &r) noexcept
 
bool contains (const QRect &r, bool proper=false) const noexcept
 
bool contains (const QPoint &p, bool proper=false) const noexcept
 
bool contains (int x, int y) const noexcept
 
bool contains (int x, int y, bool proper) const noexcept
 
QRect united (const QRect &other) const noexcept
 
QRect intersected (const QRect &other) const noexcept
 
bool intersects (const QRect &r) const noexcept
 
constexpr QRect marginsAdded (const QMargins &margins) const noexcept
 
constexpr QRect marginsRemoved (const QMargins &margins) const noexcept
 
constexpr QRectoperator+= (const QMargins &margins) noexcept
 
constexpr QRectoperator-= (const QMargins &margins) noexcept
 

Static Public Member Functions

static constexpr QRect span (const QPoint &p1, const QPoint &p2) noexcept
 

Friends

constexpr friend bool operator== (const QRect &r1, const QRect &r2) noexcept
 
constexpr friend bool operator!= (const QRect &r1, const QRect &r2) noexcept
 
constexpr friend size_t qHash (const QRect &, size_t) noexcept
 

Related Functions

(Note that these are not member functions.)

QRect operator+ (const QRect &rectangle, const QMargins &margins)
 
QRect operator+ (const QMargins &margins, const QRect &rectangle)
 
QRect operator- (const QRect &lhs, const QMargins &rhs)
 
QDataStreamoperator<< (QDataStream &stream, const QRect &rectangle)
 
QDataStreamoperator>> (QDataStream &stream, QRect &rectangle)
 

Detailed Description

The QRect class defines a rectangle in the plane using integer precision.

\inmodule QtCore

\reentrant

A rectangle is normally expressed as a top-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.

A QRect can be constructed with a set of left, top, width and height integers, or from a QPoint and a QSize. The following code creates two identical rectangles.

There is a third constructor that creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it. The rationale is that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle.

The QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect also provides functions to move the rectangle relative to the various coordinates. In addition there is a moveTo() function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, the translate() function moves the rectangle the given offset relative to the current position, and the translated() function returns a translated copy of this rectangle.

The size() function returns the rectangle's dimensions as a QSize. The dimensions can also be retrieved separately using the width() and height() functions. To manipulate the dimensions use the setSize(), setWidth() or setHeight() functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example, setBottom() or setRight().

The contains() function tells whether a given point is inside the rectangle or not, and the intersects() function returns true if this rectangle intersects with a given rectangle. The QRect class also provides the intersected() function which returns the intersection rectangle, and the united() function which returns the rectangle that encloses the given rectangle and this:

\table \row

The isEmpty() function returns true if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.

Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.

Finally, QRect objects can be streamed as well as compared.

Definition at line 58 of file qrect.h.

Constructor & Destructor Documentation

◆ QRect() [1/4]

QRect::QRect ( )
inlineconstexprnoexcept

Constructs a null rectangle.

See also
isNull()

Definition at line 61 of file qrect.h.

Here is the caller graph for this function:

◆ QRect() [2/4]

constexpr QRect::QRect ( const QPoint topLeft,
const QPoint bottomRight 
)
inlineconstexprnoexcept

Constructs a rectangle with the given topLeft and bottomRight corners, both included.

If bottomRight is to higher and to the left of topLeft, the rectangle defined is instead non-inclusive of the corners.

Note
To ensure both points are included regardless of relative order, use span().
See also
setTopLeft(), setBottomRight(), span()

Definition at line 185 of file qrect.h.

◆ QRect() [3/4]

constexpr QRect::QRect ( const QPoint topLeft,
const QSize size 
)
inlineconstexprnoexcept

Constructs a rectangle with the given topLeft corner and the given size.

See also
setTopLeft(), setSize()

Definition at line 188 of file qrect.h.

◆ QRect() [4/4]

constexpr QRect::QRect ( int  x,
int  y,
int  width,
int  height 
)
inlineconstexprnoexcept

Constructs a rectangle with (x, y) as its top-left corner and the given width and height.

See also
setRect()

Definition at line 182 of file qrect.h.

Member Function Documentation

◆ adjust()

constexpr void QRect::adjust ( int  dx1,
int  dy1,
int  dx2,
int  dy2 
)
inlineconstexprnoexcept

Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.

See also
adjusted(), setRect()

Definition at line 400 of file qrect.h.

Here is the caller graph for this function:

◆ adjusted()

constexpr QRect QRect::adjusted ( int  dx1,
int  dy1,
int  dx2,
int  dy2 
) const
inlineconstexprnoexcept

Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle.

See also
adjust()

Definition at line 397 of file qrect.h.

Here is the caller graph for this function:

◆ bottom()

constexpr int QRect::bottom ( ) const
inlineconstexprnoexcept

Returns the y-coordinate of the rectangle's bottom edge.

Note that for historical reasons this function returns top() + height() - 1; use y() + height() to retrieve the true y-coordinate.

See also
setBottom(), bottomLeft(), bottomRight()

Definition at line 209 of file qrect.h.

Here is the caller graph for this function:

◆ bottomLeft()

constexpr QPoint QRect::bottomLeft ( ) const
inlineconstexprnoexcept

Returns the position of the rectangle's bottom-left corner. Note that for historical reasons this function returns QPoint(left(), top() + height() - 1).

See also
setBottomLeft(), bottom(), left()

Definition at line 257 of file qrect.h.

Here is the caller graph for this function:

◆ bottomRight()

constexpr QPoint QRect::bottomRight ( ) const
inlineconstexprnoexcept

Returns the position of the rectangle's bottom-right corner.

Note that for historical reasons this function returns QPoint(left() + width() -1, top() + height() - 1).

See also
setBottomRight(), bottom(), right()

Definition at line 251 of file qrect.h.

Here is the caller graph for this function:

◆ center()

constexpr QPoint QRect::center ( ) const
inlineconstexprnoexcept

Returns the center point of the rectangle.

See also
moveCenter()

Definition at line 260 of file qrect.h.

Here is the caller graph for this function:

◆ contains() [1/4]

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

Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).

See also
intersects()

Definition at line 823 of file qrect.cpp.

◆ contains() [2/4]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if the given rectangle is inside this rectangle. otherwise returns false. If proper is true, this function only returns true if the rectangle is entirely inside this rectangle (not on the edge).

Definition at line 887 of file qrect.cpp.

Here is the caller graph for this function:

◆ contains() [3/4]

bool QRect::contains ( int  x,
int  y 
) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if the point (x, y) is inside this rectangle, otherwise returns false.

Definition at line 425 of file qrect.h.

Here is the call graph for this function:

◆ contains() [4/4]

bool QRect::contains ( int  x,
int  y,
bool  proper 
) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if the point (x, y) is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the point is entirely inside the rectangle(not on the edge).

Definition at line 420 of file qrect.h.

Here is the call graph for this function:

◆ getCoords()

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

Extracts the position of the rectangle's top-left corner to *x1 and *y1, and the position of the bottom-right corner to *x2 and *y2.

See also
setCoords(), getRect()

Definition at line 381 of file qrect.h.

◆ getRect()

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

Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.

See also
setRect(), getCoords()

Definition at line 365 of file qrect.h.

◆ height()

constexpr int QRect::height ( ) const
inlineconstexprnoexcept

Returns the height of the rectangle.

See also
setHeight(), width(), size()

Definition at line 266 of file qrect.h.

Here is the caller graph for this function:

◆ intersected()

QRect QRect::intersected ( const QRect rectangle) const
inlinenoexcept
Since
4.2

Returns the intersection of this rectangle and the given rectangle. Note that {r.intersected(s)} is equivalent to {r & s}.

See also
intersects(), united(), operator&=()

Definition at line 442 of file qrect.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ intersects()

bool QRect::intersects ( const QRect rectangle) const
noexcept

Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel that is within both rectangles), otherwise returns false.

The intersection rectangle can be retrieved using the intersected() function.

See also
contains()

Definition at line 1101 of file qrect.cpp.

Here is the caller graph for this function:

◆ isEmpty()

constexpr bool QRect::isEmpty ( ) const
inlineconstexprnoexcept

Returns true if the rectangle is empty, otherwise returns false.

An empty rectangle has a left() > right() or top() > bottom(). An empty rectangle is not valid (i.e., isEmpty() == !isValid()).

Use the normalized() function to retrieve a rectangle where the corners are swapped.

See also
isNull(), isValid(), normalized()

Definition at line 194 of file qrect.h.

Here is the caller graph for this function:

◆ isNull()

constexpr bool QRect::isNull ( ) const
inlineconstexprnoexcept

Returns true if the rectangle is a null rectangle, otherwise returns false.

A null rectangle has both the width and the height set to 0 (i.e., right() == left() - 1 and bottom() == top() - 1). A null rectangle is also empty, and hence is not valid.

See also
isEmpty(), isValid()

Definition at line 191 of file qrect.h.

Here is the caller graph for this function:

◆ isValid()

constexpr bool QRect::isValid ( ) const
inlineconstexprnoexcept

Returns true if the rectangle is valid, otherwise returns false.

A valid rectangle has a left() <= right() and top() <= bottom(). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).

See also
isNull(), isEmpty(), normalized()

Definition at line 197 of file qrect.h.

Here is the caller graph for this function:

◆ left()

constexpr int QRect::left ( ) const
inlineconstexprnoexcept

Returns the x-coordinate of the rectangle's left edge. Equivalent to x().

See also
setLeft(), topLeft(), bottomLeft()

Definition at line 200 of file qrect.h.

Here is the caller graph for this function:

◆ marginsAdded()

constexpr QRect QRect::marginsAdded ( const QMargins margins) const
inlineconstexprnoexcept

Returns a rectangle grown by the margins.

See also
operator+=(), marginsRemoved(), operator-=()
Since
5.1

Definition at line 475 of file qrect.h.

Here is the caller graph for this function:

◆ marginsRemoved()

constexpr QRect QRect::marginsRemoved ( const QMargins margins) const
inlineconstexprnoexcept

Removes the margins from the rectangle, shrinking it.

See also
marginsAdded(), operator+=(), operator-=()
Since
5.1

Definition at line 481 of file qrect.h.

Here is the caller graph for this function:

◆ moveBottom()

constexpr void QRect::moveBottom ( int  y)
inlineconstexprnoexcept

Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate. The rectangle's size is unchanged.

See also
bottom(), setBottom(), moveTop()

Definition at line 325 of file qrect.h.

Here is the caller graph for this function:

◆ moveBottomLeft()

constexpr void QRect::moveBottomLeft ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the bottom-left corner at the given position. The rectangle's size is unchanged.

See also
setBottomLeft(), moveBottom(), moveLeft()

Definition at line 349 of file qrect.h.

Here is the caller graph for this function:

◆ moveBottomRight()

constexpr void QRect::moveBottomRight ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the bottom-right corner at the given position. The rectangle's size is unchanged.

See also
setBottomRight(), moveRight(), moveBottom()

Definition at line 337 of file qrect.h.

◆ moveCenter()

constexpr void QRect::moveCenter ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged.

See also
center()

Definition at line 355 of file qrect.h.

Here is the caller graph for this function:

◆ moveLeft()

constexpr void QRect::moveLeft ( int  x)
inlineconstexprnoexcept

Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate. The rectangle's size is unchanged.

See also
left(), setLeft(), moveRight()

Definition at line 313 of file qrect.h.

Here is the caller graph for this function:

◆ moveRight()

constexpr void QRect::moveRight ( int  x)
inlineconstexprnoexcept

Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. The rectangle's size is unchanged.

See also
right(), setRight(), moveLeft()

Definition at line 319 of file qrect.h.

Here is the caller graph for this function:

◆ moveTo() [1/2]

constexpr void QRect::moveTo ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the top-left corner at the given position.

Definition at line 305 of file qrect.h.

◆ moveTo() [2/2]

constexpr void QRect::moveTo ( int  x,
int  y 
)
inlineconstexprnoexcept

Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.

See also
translate(), moveTopLeft()

Definition at line 297 of file qrect.h.

Here is the caller graph for this function:

◆ moveTop()

constexpr void QRect::moveTop ( int  y)
inlineconstexprnoexcept

Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate. The rectangle's size is unchanged.

See also
top(), setTop(), moveBottom()

Definition at line 316 of file qrect.h.

Here is the caller graph for this function:

◆ moveTopLeft()

constexpr void QRect::moveTopLeft ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the top-left corner at the given position. The rectangle's size is unchanged.

See also
setTopLeft(), moveTop(), moveLeft()

Definition at line 331 of file qrect.h.

Here is the caller graph for this function:

◆ moveTopRight()

constexpr void QRect::moveTopRight ( const QPoint position)
inlineconstexprnoexcept

Moves the rectangle, leaving the top-right corner at the given position. The rectangle's size is unchanged.

See also
setTopRight(), moveTop(), moveRight()

Definition at line 343 of file qrect.h.

Here is the caller graph for this function:

◆ normalized()

QRect QRect::normalized ( ) const
noexcept

Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.

If width() < 0 the function swaps the left and right corners, and it swaps the top and bottom corners if height() < 0. The corners are at the same time changed from being non-inclusive to inclusive.

See also
isValid(), isEmpty()

Definition at line 309 of file qrect.cpp.

Here is the caller graph for this function:

◆ operator&()

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

Returns the intersection of this rectangle and the given rectangle. Returns an empty rectangle if there is no intersection.

See also
operator&=(), intersected()

Definition at line 1029 of file qrect.cpp.

◆ operator&=()

QRect & QRect::operator&= ( const QRect rectangle)
inlinenoexcept

Intersects this rectangle with the given rectangle.

See also
intersected(), operator&()

Definition at line 436 of file qrect.h.

◆ operator+=()

constexpr QRect & QRect::operator+= ( const QMargins margins)
inlineconstexprnoexcept

Adds the margins to the rectangle, growing it.

See also
marginsAdded(), marginsRemoved(), operator-=()
Since
5.1

Definition at line 487 of file qrect.h.

◆ operator-=()

constexpr QRect & QRect::operator-= ( const QMargins margins)
inlineconstexprnoexcept

Returns a rectangle shrunk by the margins.

See also
marginsRemoved(), operator+=(), marginsAdded()
Since
5.1

Definition at line 493 of file qrect.h.

◆ operator|()

QRect QRect::operator| ( const QRect rectangle) const
noexcept

Returns the bounding rectangle of this rectangle and the given rectangle.

See also
operator|=(), united()

Definition at line 965 of file qrect.cpp.

◆ operator|=()

QRect & QRect::operator|= ( const QRect rectangle)
inlinenoexcept

Unites this rectangle with the given rectangle.

See also
united(), operator|()

Definition at line 430 of file qrect.h.

◆ right()

constexpr int QRect::right ( ) const
inlineconstexprnoexcept

Returns the x-coordinate of the rectangle's right edge.

Note that for historical reasons this function returns left() + width() - 1; use x() + width() to retrieve the true x-coordinate.

See also
setRight(), topRight(), bottomRight()

Definition at line 206 of file qrect.h.

Here is the caller graph for this function:

◆ setBottom()

constexpr void QRect::setBottom ( int  y)
inlineconstexprnoexcept

Sets the bottom edge of the rectangle to the given y coordinate. May change the height, but will never change the top edge of the rectangle.

See also
bottom(), moveBottom(),

Definition at line 227 of file qrect.h.

Here is the caller graph for this function:

◆ setBottomLeft()

constexpr void QRect::setBottomLeft ( const QPoint position)
inlineconstexprnoexcept

Set the bottom-left corner of the rectangle to the given position. May change the size, but will never change the top-right corner of the rectangle.

See also
bottomLeft(), moveBottomLeft()

Definition at line 239 of file qrect.h.

◆ setBottomRight()

constexpr void QRect::setBottomRight ( const QPoint position)
inlineconstexprnoexcept

Set the bottom-right corner of the rectangle to the given position. May change the size, but will never change the top-left corner of the rectangle.

See also
bottomRight(), moveBottomRight()

Definition at line 233 of file qrect.h.

◆ setCoords()

constexpr void QRect::setCoords ( int  x1,
int  y1,
int  x2,
int  y2 
)
inlineconstexprnoexcept

Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2).

See also
getCoords(), setRect()

Definition at line 389 of file qrect.h.

Here is the caller graph for this function:

◆ setHeight()

constexpr void QRect::setHeight ( int  height)
inlineconstexprnoexcept

Sets the height of the rectangle to the given height. The bottom edge is changed, but not the top one.

See also
height(), setSize()

Definition at line 411 of file qrect.h.

Here is the caller graph for this function:

◆ setLeft()

constexpr void QRect::setLeft ( int  x)
inlineconstexprnoexcept

Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent to setX().

See also
left(), moveLeft()

Definition at line 218 of file qrect.h.

Here is the caller graph for this function:

◆ setRect()

constexpr void QRect::setRect ( int  x,
int  y,
int  width,
int  height 
)
inlineconstexprnoexcept

Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given width and height.

See also
getRect(), setCoords()

Definition at line 373 of file qrect.h.

Here is the caller graph for this function:

◆ setRight()

constexpr void QRect::setRight ( int  x)
inlineconstexprnoexcept

Sets the right edge of the rectangle to the given x coordinate. May change the width, but will never change the left edge of the rectangle.

See also
right(), moveRight()

Definition at line 224 of file qrect.h.

Here is the caller graph for this function:

◆ setSize()

constexpr void QRect::setSize ( const QSize size)
inlineconstexprnoexcept

Sets the size of the rectangle to the given size. The top-left corner is not moved.

See also
size(), setWidth(), setHeight()

Definition at line 414 of file qrect.h.

Here is the caller graph for this function:

◆ setTop()

constexpr void QRect::setTop ( int  y)
inlineconstexprnoexcept

Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent to setY().

See also
top(), moveTop()

Definition at line 221 of file qrect.h.

Here is the caller graph for this function:

◆ setTopLeft()

constexpr void QRect::setTopLeft ( const QPoint position)
inlineconstexprnoexcept

Set the top-left corner of the rectangle to the given position. May change the size, but will never change the bottom-right corner of the rectangle.

See also
topLeft(), moveTopLeft()

Definition at line 230 of file qrect.h.

◆ setTopRight()

constexpr void QRect::setTopRight ( const QPoint position)
inlineconstexprnoexcept

Set the top-right corner of the rectangle to the given position. May change the size, but will never change the bottom-left corner of the rectangle.

See also
topRight(), moveTopRight()

Definition at line 236 of file qrect.h.

◆ setWidth()

constexpr void QRect::setWidth ( int  width)
inlineconstexprnoexcept

Sets the width of the rectangle to the given width. The right edge is changed, but not the left one.

See also
width(), setSize()

Definition at line 408 of file qrect.h.

Here is the caller graph for this function:

◆ setX()

constexpr void QRect::setX ( int  x)
inlineconstexprnoexcept

Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent to setLeft().

See also
x(), setY(), setTopLeft()

Definition at line 242 of file qrect.h.

Here is the caller graph for this function:

◆ setY()

constexpr void QRect::setY ( int  y)
inlineconstexprnoexcept

Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent to setTop().

See also
y(), setX(), setTopLeft()

Definition at line 245 of file qrect.h.

◆ size()

constexpr QSize QRect::size ( ) const
inlineconstexprnoexcept

Returns the size of the rectangle.

See also
setSize(), width(), height()

Definition at line 269 of file qrect.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ span()

constexpr QRect QRect::span ( const QPoint p1,
const QPoint p2 
)
inlinestaticconstexprnoexcept

Returns a rectangle spanning the two points p1 and p2, including both and everything in between.

Since
6.0

Definition at line 499 of file qrect.h.

Here is the caller graph for this function:

◆ top()

constexpr int QRect::top ( ) const
inlineconstexprnoexcept

Returns the y-coordinate of the rectangle's top edge. Equivalent to y().

See also
setTop(), topLeft(), topRight()

Definition at line 203 of file qrect.h.

Here is the caller graph for this function:

◆ topLeft()

constexpr QPoint QRect::topLeft ( ) const
inlineconstexprnoexcept

Returns the position of the rectangle's top-left corner.

See also
setTopLeft(), top(), left()

Definition at line 248 of file qrect.h.

Here is the caller graph for this function:

◆ topRight()

constexpr QPoint QRect::topRight ( ) const
inlineconstexprnoexcept

Returns the position of the rectangle's top-right corner.

Note that for historical reasons this function returns QPoint(left() + width() -1, top()).

See also
setTopRight(), top(), right()

Definition at line 254 of file qrect.h.

Here is the caller graph for this function:

◆ translate() [1/2]

constexpr void QRect::translate ( const QPoint offset)
inlineconstexprnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Moves the rectangle {offset}.\l{QPoint::x()}{x()} along the x axis and {offset}.\l{QPoint::y()}{y()} along the y axis, relative to the current position.

Definition at line 280 of file qrect.h.

◆ translate() [2/2]

constexpr void QRect::translate ( int  dx,
int  dy 
)
inlineconstexprnoexcept

Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See also
moveTopLeft(), moveTo(), translated()

Definition at line 272 of file qrect.h.

Here is the caller graph for this function:

◆ translated() [1/2]

constexpr QRect QRect::translated ( const QPoint offset) const
inlineconstexprnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a copy of the rectangle that is translated {offset}.\l{QPoint::x()}{x()} along the x axis and {offset}.\l{QPoint::y()}{y()} along the y axis, relative to the current position.

Definition at line 291 of file qrect.h.

◆ translated() [2/2]

constexpr QRect QRect::translated ( int  dx,
int  dy 
) const
inlineconstexprnoexcept

Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See also
translate()

Definition at line 288 of file qrect.h.

Here is the caller graph for this function:

◆ transposed()

constexpr QRect QRect::transposed ( ) const
inlineconstexprnoexcept
Since
5.7

Returns a copy of the rectangle that has its width and height exchanged:

See also
QSize::transposed()

Definition at line 294 of file qrect.h.

Here is the call graph for this function:

◆ united()

QRect QRect::united ( const QRect rectangle) const
inlinenoexcept
Since
4.2

Returns the bounding rectangle of this rectangle and the given rectangle.

See also
intersected()

Definition at line 447 of file qrect.h.

Here is the caller graph for this function:

◆ width()

constexpr int QRect::width ( ) const
inlineconstexprnoexcept

Returns the width of the rectangle.

See also
setWidth(), height(), size()

Definition at line 263 of file qrect.h.

Here is the caller graph for this function:

◆ x()

constexpr int QRect::x ( ) const
inlineconstexprnoexcept

Returns the x-coordinate of the rectangle's left edge. Equivalent to left().

See also
setX(), y(), topLeft()

Definition at line 212 of file qrect.h.

Here is the caller graph for this function:

◆ y()

constexpr int QRect::y ( ) const
inlineconstexprnoexcept

Returns the y-coordinate of the rectangle's top edge. Equivalent to top().

See also
setY(), x(), topLeft()

Definition at line 215 of file qrect.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QRect::operator!= ( const QRect r1,
const QRect r2 
)
friend

Returns true if the rectangles r1 and r2 are different, otherwise returns false.

Definition at line 153 of file qrect.h.

◆ operator+() [1/2]

QRect operator+ ( const QMargins margins,
const QRect rectangle 
)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the rectangle grown by the margins.

Since
5.1

Definition at line 463 of file qrect.h.

◆ operator+() [2/2]

QRect operator+ ( const QRect rectangle,
const QMargins margins 
)
related

Returns the rectangle grown by the margins.

Since
5.1

Definition at line 457 of file qrect.h.

◆ operator-()

QRect operator- ( const QRect lhs,
const QMargins rhs 
)
related

Returns the lhs rectangle shrunk by the rhs margins.

Since
5.3

Definition at line 469 of file qrect.h.

◆ operator<<()

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

Writes the given rectangle to the given stream, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1249 of file qrect.cpp.

◆ operator==

bool QRect::operator== ( const QRect r1,
const QRect r2 
)
friend

Returns true if the rectangles r1 and r2 are equal, otherwise returns false.

Definition at line 151 of file qrect.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QRect rectangle 
)
related

Reads a rectangle from the given stream into the given rectangle, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1270 of file qrect.cpp.

◆ qHash

constexpr friend size_t qHash ( const QRect r,
size_t  seed = 0 
)
friend

Definition at line 452 of file qrect.h.


The documentation for this class was generated from the following files: