![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore\reentrant More...
#include <qrect.h>
Public Member Functions | |
constexpr | QRect () noexcept |
Constructs a null rectangle. | |
constexpr | QRect (const QPoint &topleft, const QPoint &bottomright) noexcept |
Constructs a rectangle with the given topLeft and bottomRight corners, both included. | |
constexpr | QRect (const QPoint &topleft, const QSize &size) noexcept |
Constructs a rectangle with the given topLeft corner and the given size. | |
constexpr | QRect (int left, int top, int width, int height) noexcept |
Constructs a rectangle with (x, y) as its top-left corner and the given width and height. | |
constexpr bool | isNull () const noexcept |
Returns true if the rectangle is a null rectangle, otherwise returns false . | |
constexpr bool | isEmpty () const noexcept |
Returns true if the rectangle is empty, otherwise returns false . | |
constexpr bool | isValid () const noexcept |
Returns true if the rectangle is valid, otherwise returns false . | |
constexpr int | left () const noexcept |
Returns the x-coordinate of the rectangle's left edge. | |
constexpr int | top () const noexcept |
Returns the y-coordinate of the rectangle's top edge. | |
constexpr int | right () const noexcept |
Returns the x-coordinate of the rectangle's right edge. | |
constexpr int | bottom () const noexcept |
Returns the y-coordinate of the rectangle's bottom edge. | |
QRect | normalized () const noexcept |
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height. | |
constexpr int | x () const noexcept |
Returns the x-coordinate of the rectangle's left edge. | |
constexpr int | y () const noexcept |
Returns the y-coordinate of the rectangle's top edge. | |
constexpr void | setLeft (int pos) noexcept |
Sets the left edge of the rectangle to the given x coordinate. | |
constexpr void | setTop (int pos) noexcept |
Sets the top edge of the rectangle to the given y coordinate. | |
constexpr void | setRight (int pos) noexcept |
Sets the right edge of the rectangle to the given x coordinate. | |
constexpr void | setBottom (int pos) noexcept |
Sets the bottom edge of the rectangle to the given y coordinate. | |
constexpr void | setX (int x) noexcept |
Sets the left edge of the rectangle to the given x coordinate. | |
constexpr void | setY (int y) noexcept |
Sets the top edge of the rectangle to the given y coordinate. | |
constexpr void | setTopLeft (const QPoint &p) noexcept |
Set the top-left corner of the rectangle to the given position. | |
constexpr void | setBottomRight (const QPoint &p) noexcept |
Set the bottom-right corner of the rectangle to the given position. | |
constexpr void | setTopRight (const QPoint &p) noexcept |
Set the top-right corner of the rectangle to the given position. | |
constexpr void | setBottomLeft (const QPoint &p) noexcept |
Set the bottom-left corner of the rectangle to the given position. | |
constexpr QPoint | topLeft () const noexcept |
Returns the position of the rectangle's top-left corner. | |
constexpr QPoint | bottomRight () const noexcept |
Returns the position of the rectangle's bottom-right corner. | |
constexpr QPoint | topRight () const noexcept |
Returns the position of the rectangle's top-right corner. | |
constexpr QPoint | bottomLeft () const noexcept |
Returns the position of the rectangle's bottom-left corner. | |
constexpr QPoint | center () const noexcept |
Returns the center point of the rectangle. | |
constexpr void | moveLeft (int pos) noexcept |
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate. | |
constexpr void | moveTop (int pos) noexcept |
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate. | |
constexpr void | moveRight (int pos) noexcept |
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. | |
constexpr void | moveBottom (int pos) noexcept |
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate. | |
constexpr void | moveTopLeft (const QPoint &p) noexcept |
Moves the rectangle, leaving the top-left corner at the given position. | |
constexpr void | moveBottomRight (const QPoint &p) noexcept |
Moves the rectangle, leaving the bottom-right corner at the given position. | |
constexpr void | moveTopRight (const QPoint &p) noexcept |
Moves the rectangle, leaving the top-right corner at the given position. | |
constexpr void | moveBottomLeft (const QPoint &p) noexcept |
Moves the rectangle, leaving the bottom-left corner at the given position. | |
constexpr void | moveCenter (const QPoint &p) noexcept |
Moves the rectangle, leaving the center point at the given position. | |
constexpr void | translate (int dx, int dy) noexcept |
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. | |
constexpr void | translate (const QPoint &p) noexcept |
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}. | |
constexpr QRect | translated (int dx, int dy) const noexcept |
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. | |
constexpr QRect | translated (const QPoint &p) 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 a copy of the rectangle that is translated {offset}. | |
constexpr QRect | transposed () const noexcept |
constexpr void | moveTo (int x, int t) noexcept |
Moves the rectangle, leaving the top-left corner at the given position (x, y). | |
constexpr void | moveTo (const QPoint &p) noexcept |
Moves the rectangle, leaving the top-left corner at the given position. | |
constexpr void | setRect (int x, int y, int w, int h) noexcept |
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given width and height. | |
constexpr void | getRect (int *x, int *y, int *w, int *h) const |
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height. | |
constexpr void | setCoords (int x1, int y1, int x2, int y2) noexcept |
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2). | |
constexpr void | getCoords (int *x1, int *y1, int *x2, int *y2) const |
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. | |
constexpr void | adjust (int x1, int y1, int x2, int y2) noexcept |
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle. | |
constexpr QRect | adjusted (int x1, int y1, int x2, int y2) const noexcept |
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle. | |
constexpr QSize | size () const noexcept |
Returns the size of the rectangle. | |
constexpr int | width () const noexcept |
Returns the width of the rectangle. | |
constexpr int | height () const noexcept |
Returns the height of the rectangle. | |
constexpr void | setWidth (int w) noexcept |
Sets the width of the rectangle to the given width. | |
constexpr void | setHeight (int h) noexcept |
Sets the height of the rectangle to the given height. | |
constexpr void | setSize (const QSize &s) noexcept |
Sets the size of the rectangle to the given size. | |
QRect | operator| (const QRect &r) const noexcept |
Returns the bounding rectangle of this rectangle and the given rectangle. | |
QRect | operator& (const QRect &r) const noexcept |
Returns the intersection of this rectangle and the given rectangle. | |
QRect & | operator|= (const QRect &r) noexcept |
Unites this rectangle with the given rectangle. | |
QRect & | operator&= (const QRect &r) noexcept |
Intersects this rectangle with the given rectangle. | |
bool | contains (const QRect &r, 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. | |
bool | contains (const QPoint &p, bool proper=false) const noexcept |
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false . | |
bool | contains (int x, int y) 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 point (x, y) is inside this rectangle, otherwise returns false . | |
bool | contains (int x, int y, bool proper) 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 point (x, y) is inside or on the edge of the rectangle, otherwise returns false . | |
QRect | united (const QRect &other) const noexcept |
QRect | intersected (const QRect &other) const noexcept |
bool | intersects (const QRect &r) 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 . | |
constexpr QRect | marginsAdded (const QMargins &margins) const noexcept |
Returns a rectangle grown by the margins. | |
constexpr QRect | marginsRemoved (const QMargins &margins) const noexcept |
Removes the margins from the rectangle, shrinking it. | |
constexpr QRect & | operator+= (const QMargins &margins) noexcept |
Adds the margins to the rectangle, growing it. | |
constexpr QRect & | operator-= (const QMargins &margins) noexcept |
Returns a rectangle shrunk by the margins. | |
constexpr QRectF | toRectF () const noexcept |
Static Public Member Functions | |
static constexpr QRect | span (const QPoint &p1, const QPoint &p2) noexcept |
Returns a rectangle spanning the two points p1 and p2, including both and everything in between. | |
Friends | |
constexpr bool | comparesEqual (const QRect &r1, const QRect &r2) noexcept |
constexpr size_t | qHash (const QRect &r, size_t seed=0) |
Related Symbols | |
(Note that these are not member symbols.) | |
QRect | operator+ (const QRect &rectangle, const QMargins &margins) |
Returns the rectangle grown by the margins. | |
QRect | operator+ (const QMargins &margins, const QRect &rectangle) |
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. | |
QRect | operator- (const QRect &lhs, const QMargins &rhs) |
Returns the lhs rectangle shrunk by the rhs margins. | |
QDataStream & | operator<< (QDataStream &stream, const QRect &rectangle) |
Writes the given rectangle to the given stream, and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &stream, QRect &rectangle) |
Reads a rectangle from the given stream into the given rectangle, and returns a reference to the stream. | |
\inmodule QtCore
\reentrant
\compares equality \compareswith equality QRectF \endcompareswith
The QRect class defines a rectangle in the plane using integer precision.
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.
|
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.
Constructs a rectangle with the given topLeft corner and the given size.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
|
inlinenodiscardconstexprnoexcept |
|
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.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns the center point of the rectangle.
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).
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).
|
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
.
|
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).
|
inlineconstexpr |
|
inlineconstexpr |
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.
|
inlineconstexprnoexcept |
Returns the height of the rectangle.
Returns the intersection of this rectangle and the given rectangle. Note that {r.intersected(s)} is equivalent to
{r & s}.
|
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.
|
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.
|
inlineconstexprnoexcept |
|
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()).
|
inlineconstexprnoexcept |
Returns a rectangle grown by the margins.
Removes the margins from the rectangle, shrinking it.
|
inlineconstexprnoexcept |
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate.
The rectangle's size is unchanged.
Moves the rectangle, leaving the bottom-left corner at the given position.
The rectangle's size is unchanged.
Moves the rectangle, leaving the bottom-right corner at the given position.
The rectangle's size is unchanged.
|
inlineconstexprnoexcept |
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate.
The rectangle's size is unchanged.
|
inlineconstexprnoexcept |
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate.
The rectangle's size is unchanged.
|
inlineconstexprnoexcept |
Moves the rectangle, leaving the top-left corner at the given position (x, y).
The rectangle's size is unchanged.
|
inlineconstexprnoexcept |
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
The rectangle's size is unchanged.
Moves the rectangle, leaving the top-left corner at the given position.
The rectangle's size is unchanged.
Moves the rectangle, leaving the top-right corner at the given position.
The rectangle's size is unchanged.
|
nodiscardnoexcept |
Returns the intersection of this rectangle and the given rectangle.
Returns an empty rectangle if there is no intersection.
Intersects this rectangle with the given rectangle.
Adds the margins to the rectangle, growing it.
Returns a rectangle shrunk by the margins.
Returns the bounding rectangle of this rectangle and the given rectangle.
Unites this rectangle with the given rectangle.
|
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.
|
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.
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.
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.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
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().
|
inlineconstexprnoexcept |
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given width and height.
|
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.
Sets the size of the rectangle to the given size.
The top-left corner is not moved.
|
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.
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.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns the position of the rectangle's top-left corner.
|
inlineconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Returns this rectangle as a rectangle with floating point accuracy.
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.
|
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.
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.
|
inlinenodiscardconstexprnoexcept |
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.
|
inlinenodiscardconstexprnoexcept |
Returns the bounding rectangle of this rectangle and the given rectangle.
|
inlineconstexprnoexcept |
Returns the width of the rectangle.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
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.
|
|