QtBase
v6.3.1
|
The QRectF class defines a finite rectangle in the plane using floating point precision. More...
#include <qrect.h>
Public Member Functions | |
constexpr | QRectF () noexcept |
constexpr | QRectF (const QPointF &topleft, const QSizeF &size) noexcept |
constexpr | QRectF (const QPointF &topleft, const QPointF &bottomRight) noexcept |
constexpr | QRectF (qreal left, qreal top, qreal width, qreal height) noexcept |
constexpr | QRectF (const QRect &rect) noexcept |
constexpr bool | isNull () const noexcept |
constexpr bool | isEmpty () const noexcept |
constexpr bool | isValid () const noexcept |
QRectF | normalized () const noexcept |
constexpr qreal | left () const noexcept |
constexpr qreal | top () const noexcept |
constexpr qreal | right () const noexcept |
constexpr qreal | bottom () const noexcept |
constexpr qreal | x () const noexcept |
constexpr qreal | y () const noexcept |
constexpr void | setLeft (qreal pos) noexcept |
constexpr void | setTop (qreal pos) noexcept |
constexpr void | setRight (qreal pos) noexcept |
constexpr void | setBottom (qreal pos) noexcept |
constexpr void | setX (qreal pos) noexcept |
constexpr void | setY (qreal pos) noexcept |
constexpr QPointF | topLeft () const noexcept |
constexpr QPointF | bottomRight () const noexcept |
constexpr QPointF | topRight () const noexcept |
constexpr QPointF | bottomLeft () const noexcept |
constexpr QPointF | center () const noexcept |
constexpr void | setTopLeft (const QPointF &p) noexcept |
constexpr void | setBottomRight (const QPointF &p) noexcept |
constexpr void | setTopRight (const QPointF &p) noexcept |
constexpr void | setBottomLeft (const QPointF &p) noexcept |
constexpr void | moveLeft (qreal pos) noexcept |
constexpr void | moveTop (qreal pos) noexcept |
constexpr void | moveRight (qreal pos) noexcept |
constexpr void | moveBottom (qreal pos) noexcept |
constexpr void | moveTopLeft (const QPointF &p) noexcept |
constexpr void | moveBottomRight (const QPointF &p) noexcept |
constexpr void | moveTopRight (const QPointF &p) noexcept |
constexpr void | moveBottomLeft (const QPointF &p) noexcept |
constexpr void | moveCenter (const QPointF &p) noexcept |
constexpr void | translate (qreal dx, qreal dy) noexcept |
constexpr void | translate (const QPointF &p) noexcept |
constexpr QRectF | translated (qreal dx, qreal dy) const noexcept |
constexpr QRectF | translated (const QPointF &p) const noexcept |
constexpr QRectF | transposed () const noexcept |
constexpr void | moveTo (qreal x, qreal y) noexcept |
constexpr void | moveTo (const QPointF &p) noexcept |
constexpr void | setRect (qreal x, qreal y, qreal w, qreal h) noexcept |
constexpr void | getRect (qreal *x, qreal *y, qreal *w, qreal *h) const |
constexpr void | setCoords (qreal x1, qreal y1, qreal x2, qreal y2) noexcept |
constexpr void | getCoords (qreal *x1, qreal *y1, qreal *x2, qreal *y2) const |
constexpr void | adjust (qreal x1, qreal y1, qreal x2, qreal y2) noexcept |
constexpr QRectF | adjusted (qreal x1, qreal y1, qreal x2, qreal y2) const noexcept |
constexpr QSizeF | size () const noexcept |
constexpr qreal | width () const noexcept |
constexpr qreal | height () const noexcept |
constexpr void | setWidth (qreal w) noexcept |
constexpr void | setHeight (qreal h) noexcept |
constexpr void | setSize (const QSizeF &s) noexcept |
QRectF | operator| (const QRectF &r) const noexcept |
QRectF | operator& (const QRectF &r) const noexcept |
QRectF & | operator|= (const QRectF &r) noexcept |
QRectF & | operator&= (const QRectF &r) noexcept |
bool | contains (const QRectF &r) const noexcept |
bool | contains (const QPointF &p) const noexcept |
bool | contains (qreal x, qreal y) const noexcept |
QRectF | united (const QRectF &other) const noexcept |
QRectF | intersected (const QRectF &other) const noexcept |
bool | intersects (const QRectF &r) const noexcept |
constexpr QRectF | marginsAdded (const QMarginsF &margins) const noexcept |
constexpr QRectF | marginsRemoved (const QMarginsF &margins) const noexcept |
constexpr QRectF & | operator+= (const QMarginsF &margins) noexcept |
constexpr QRectF & | operator-= (const QMarginsF &margins) noexcept |
constexpr QRect | toRect () const noexcept |
QRect | toAlignedRect () const noexcept |
Friends | |
constexpr friend bool | operator== (const QRectF &r1, const QRectF &r2) noexcept |
constexpr friend bool | operator!= (const QRectF &r1, const QRectF &r2) noexcept |
Related Functions | |
(Note that these are not member functions.) | |
QRectF | operator+ (const QRectF &lhs, const QMarginsF &rhs) |
QRectF | operator- (const QRectF &lhs, const QMarginsF &rhs) |
QRectF | operator+ (const QMarginsF &lhs, const QRectF &rhs) |
QDataStream & | operator<< (QDataStream &stream, const QRectF &rectangle) |
QDataStream & | operator>> (QDataStream &stream, QRectF &rectangle) |
The QRectF class defines a finite rectangle in the plane using floating point precision.
\inmodule QtCore
\reentrant
A rectangle is normally expressed as a top-left corner and a size. The size (width and height) of a QRectF is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRectF can be constructed with a set of left, top, width and height coordinates, or from a QPointF and a QSizeF. The following code creates two identical rectangles.
There is also a third constructor creating a QRectF from a QRect, and a corresponding toRect() function that returns a QRect object based on the values of this rectangle (note that the coordinates in the returned rectangle are rounded to the nearest integer).
The QRectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRectF 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 QSizeF. 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 (otherwise false). The QRectF 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 the rectangle's width or height is less than, or equal to, 0. Note that an empty rectangle is not valid: The isValid() function returns true
if both width and height is larger than 0. 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 QRectF is defined in essentially the same way as QRect.
Finally, QRectF objects can be streamed as well as compared.
|
inlineconstexprnoexcept |
Constructs a rectangle with the given topLeft corner and the given size.
|
inlineconstexprnoexcept |
Constructs a rectangle with the given topLeft and bottomRight corners.
|
inlineconstexprnoexcept |
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle. All parameters must be finite.
Definition at line 814 of file qrect.h.
|
inlineconstexprnoexcept |
Returns the y-coordinate of the rectangle's bottom edge.
Definition at line 527 of file qrect.h.
|
inlineconstexprnoexcept |
Returns the position of the rectangle's bottom-left corner.
|
inlineconstexprnoexcept |
Returns the position of the rectangle's bottom-right corner.
Definition at line 539 of file qrect.h.
|
inlineconstexprnoexcept |
Returns the center point of the rectangle.
Definition at line 708 of file qrect.h.
Returns true
if the given point is inside or on the edge of the rectangle; otherwise returns false
.
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
.
Definition at line 2006 of file qrect.cpp.
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
.
Definition at line 839 of file qrect.h.
|
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.
|
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.
Definition at line 741 of file qrect.h.
Returns the intersection of this rectangle and the given rectangle. Note that {r.intersected(s)}
is equivalent to {r
& s}.
Definition at line 856 of file qrect.h.
Returns true
if this rectangle intersects with the given rectangle (i.e. there is a non-empty area of overlap between them), otherwise returns false
.
The intersection rectangle can be retrieved using the intersected() function.
Definition at line 2284 of file qrect.cpp.
|
inlineconstexprnoexcept |
Returns true
if the rectangle is empty, otherwise returns false
.
An empty rectangle has width() <= 0 or height() <= 0. An empty rectangle is not valid (i.e., isEmpty() == !isValid()).
Use the normalized() function to retrieve a rectangle where the corners are swapped.
Definition at line 670 of file qrect.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns true
if the rectangle is valid, otherwise returns false
.
A valid rectangle has a width() > 0 and height() > 0. Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).
Definition at line 675 of file qrect.h.
|
inlineconstexprnoexcept |
Returns a rectangle grown by the margins.
Removes the margins from the rectangle, shrinking it.
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given finite 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.
Moves the rectangle horizontally, leaving the rectangle's left edge at the given finite x coordinate. The rectangle's size is unchanged.
Definition at line 711 of file qrect.h.
Moves the rectangle horizontally, leaving the rectangle's right edge at the given finite x coordinate. The rectangle's size is unchanged.
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged. Both parameters must be finite.
Definition at line 759 of file qrect.h.
Moves the rectangle vertically, leaving the rectangle's top line at the given finite y coordinate. The rectangle's size is unchanged.
Definition at line 714 of file qrect.h.
Moves the rectangle, leaving the top-left corner at the given position. The rectangle's size is unchanged.
Definition at line 723 of file qrect.h.
Moves the rectangle, leaving the top-right corner at the given position. The rectangle's size is unchanged.
|
noexcept |
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.
Definition at line 526 of file qrect.h.
Sets the bottom edge of the rectangle to the given finite y coordinate. May change the height, but will never change the top edge of the rectangle.
Definition at line 693 of file qrect.h.
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.
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2). All parameters must be finite.
Sets the left edge of the rectangle to the given finite x coordinate. May change the width, but will never change the right edge of the rectangle.
Equivalent to setX().
Definition at line 684 of file qrect.h.
|
inlineconstexprnoexcept |
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width and height. All parameters must be finite.
Definition at line 790 of file qrect.h.
Sets the right edge of the rectangle to the given finite x coordinate. May change the width, but will never change the left edge of the rectangle.
Definition at line 687 of file qrect.h.
Sets the size of the rectangle to the given finite size. The top-left corner is not moved.
Definition at line 833 of file qrect.h.
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 |
|
noexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns the position of the rectangle's top-left corner.
Definition at line 538 of file qrect.h.
|
inlineconstexprnoexcept |
Returns the position of the rectangle's top-right corner.
|
inlineconstexprnoexcept |
Returns a QRect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer.
Definition at line 866 of file qrect.h.
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{QPointF::x()}{x()} along the x axis and {offset}.\l{QPointF::y()}{y()} along the y axis, relative to the current position.
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 downwards. Both parameters must be finite.
Definition at line 747 of file qrect.h.
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{QPointF::x()}{x()} along the x axis and {offset}.\l{QPointF::y()}{y()} along the y axis, relative to the current position.
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. Both parameters must be finite.
Definition at line 771 of file qrect.h.
|
inlineconstexprnoexcept |
Returns a copy of the rectangle that has its width and height exchanged:
Definition at line 779 of file qrect.h.
Returns the bounding rectangle of this rectangle and the given rectangle.
|
inlineconstexprnoexcept |
Returns the width of the rectangle.
Definition at line 738 of file qrect.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
friend |
|
related |
Returns true
if the rectangles r1 and r2 are approximately equal, otherwise returns false
.
|
related |