QRectF Class
The QRectF class defines a rectangle in the plane using floating point precision. More…
| Header | #include <QRectF> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QRectF() | |
| QRectF(double left, double top, double width, double height) | |
| QRectF(const QPointF &topLeft, const QSizeF &s) | |
| QRectF(const QPointF &topLeft, const QPointF &bottomRight) | |
| QRectF(const QRect &r) | |
| bool | isNull() const |
| bool | isEmpty() const |
| bool | isValid() const |
| double | x() const |
| double | y() const |
| double | width() const |
| double | height() const |
| double | left() const |
| double | top() const |
| double | right() const |
| double | bottom() const |
| QSizeF | size() const |
| QPointF | topLeft() const |
| QPointF | bottomRight() const |
| QPointF | topRight() const |
| QPointF | bottomLeft() const |
| QPointF | center() const |
| void | setX(double v) |
| void | setY(double v) |
| void | setLeft(double v) |
| void | setTop(double v) |
| void | setRight(double v) |
| void | setBottom(double v) |
| void | setTopLeft(const QPointF &p) |
| void | setBottomRight(const QPointF &p) |
| void | setTopRight(const QPointF &p) |
| void | setBottomLeft(const QPointF &p) |
| void | getRect(double *x, double *y, double *width, double *height) const |
| void | getCoords(double *x1, double *y1, double *x2, double *y2) const |
| void | setWidth(double v) |
| void | setHeight(double v) |
| void | setSize(const QSizeF &s) |
| void | setRect(double x, double y, double wd, double ht) |
| void | setCoords(double xa, double ya, double xb, double yb) |
| void | moveLeft(double p) |
| void | moveTop(double p) |
| void | moveRight(double p) |
| void | moveTopLeft(const QPointF &p) |
| void | moveBottomRight(const QPointF &p) |
| void | moveTopRight(const QPointF &p) |
| void | moveBottomLeft(const QPointF &p) |
| void | moveBottom(double p) |
| void | moveTo(double x, double y) |
| void | moveTo(const QPointF &p) |
| void | moveCenter(const QPointF &p) |
| void | translate(double dx, double dy) |
| void | translate(const QPointF &p) |
| QRectF | translated(double dx, double dy) const |
| QRectF | translated(const QPointF &p) const |
| QRectF | transposed() const |
| void | adjust(double a, double b, double c, double d) |
| QRectF | adjusted(double a, double b, double c, double d) const |
| QRectF | marginsAdded(const QMarginsF &m) const |
| QRectF | marginsRemoved(const QMarginsF &m) const |
| QRectF | normalized() const |
| bool | contains(const QPointF &p) const |
| bool | contains(double x, double y) const |
| bool | contains(const QRectF &o) const |
| QRectF | united(const QRectF &o) const |
| QRectF | intersected(const QRectF &o) const |
| bool | intersects(const QRectF &o) const |
| QRect | toRect() const |
| QRect | toAlignedRect() const |
| QRectF | operator|(const QRectF &o) const |
| QRectF | operator&(const QRectF &o) const |
| QRectF & | operator|=(const QRectF &o) |
| QRectF & | operator&=(const QRectF &o) |
| QRectF & | operator+=(const QMarginsF &m) |
| QRectF & | operator-=(const QMarginsF &m) |
Detailed Description
A rectangle is stored as the position of its top-left corner and its width and height, all as double. Unlike QRect, the right and bottom edges are exclusive: right() is left() + width() and bottom() is top() + height(). Use QRect for integer coordinates.
A rectangle is valid when both its width and height are greater than 0. Use normalized() to obtain an equivalent rectangle with non-negative width and height.
See also QRect, QPointF, QSizeF and QMarginsF.
Differences from Qt
Coordinates are always double, which is what qreal is in Nt.
Member Function Documentation
QRectF::QRectF()
Constructs a null rectangle, with zero width and height.
See also isNull().
QRectF::QRectF(double left, double top, double width, double height)
Constructs a rectangle with left, top as its top-left corner and the given width and height.
QRectF::QRectF(const QPointF &topLeft, const QSizeF &s)
Constructs a rectangle with the given topLeft corner and the given size s.
QRectF::QRectF(const QPointF &topLeft, const QPointF &bottomRight)
Constructs a rectangle with the given topLeft and bottomRight corners.
QRectF::QRectF(const QRect &r)
Constructs a QRectF rectangle from the given integer rectangle r. The right and bottom edges of the result are exclusive, so its width and height equal those of r.
See also toRect().
void QRectF::adjust(double a, double b, double c, double d)
Adds a, b, c and d to the left, top, right and bottom coordinates of the rectangle respectively.
See also adjusted() and setRect().
QRectF QRectF::adjusted(double a, double b, double c, double d) const
Returns a copy of the rectangle with a, b, c and d added to the left, top, right and bottom coordinates respectively.
See also adjust().
double QRectF::bottom() const
Returns the y coordinate of the rectangle's bottom edge, which is top() + height().
See also setBottom() and top().
QPointF QRectF::bottomLeft() const
Returns the position of the rectangle's bottom-left corner.
See also topRight().
QPointF QRectF::bottomRight() const
Returns the position of the rectangle's bottom-right corner.
See also topLeft().
QPointF QRectF::center() const
Returns the center point of the rectangle.
See also moveCenter().
bool QRectF::contains(const QPointF &p) const
Returns true if the given point p is inside or on the edge of the rectangle; otherwise returns false. A rectangle with zero width or height contains nothing.
See also intersects().
bool QRectF::contains(double x, double y) const
This is an overloaded function.
Returns true if the point (x, y) is inside or on the edge of this rectangle.
bool QRectF::contains(const QRectF &o) const
This is an overloaded function.
Returns true if the rectangle o is inside this rectangle; otherwise returns false. A rectangle with zero width or height never contains, and is never contained by, another rectangle.
void QRectF::getCoords(double *x1, double *y1, double *x2, double *y2) const
Stores the top-left corner in *x1 and *y1 and the bottom-right corner in *x2 and *y2, through x1, y1, x2 and y2.
See also getRect().
void QRectF::getRect(double *x, double *y, double *width, double *height) const
Stores the position of the top-left corner in *x and *y and the size in *width and *height, through x, y, width and height.
See also getCoords().
double QRectF::height() const
Returns the height of the rectangle.
See also setHeight() and width().
QRectF QRectF::intersected(const QRectF &o) const
Returns the intersection of this rectangle and the rectangle o. Returns a null rectangle if they do not intersect.
See also intersects() and united().
bool QRectF::intersects(const QRectF &o) const
Returns true if this rectangle intersects the rectangle o, that is, if they share an area of non-zero size; otherwise returns false.
See also intersected() and contains().
bool QRectF::isEmpty() const
Returns true if the rectangle is empty, that is, its width or height is less than or equal to 0; otherwise returns false.
See also isNull() and isValid().
bool QRectF::isNull() const
Returns true if the rectangle is a null rectangle, that is, its width and height are both exactly 0; otherwise returns false.
See also isEmpty() and isValid().
bool QRectF::isValid() const
Returns true if the rectangle is valid, that is, its width and height are both greater than 0; otherwise returns false.
See also isNull(), isEmpty() and normalized().
double QRectF::left() const
Returns the x coordinate of the rectangle's left edge. Equivalent to x().
See also setLeft() and right().
QRectF QRectF::marginsAdded(const QMarginsF &m) const
Returns a rectangle grown by the margins m: the left and top edges move outwards by the left and top margins, the right and bottom edges by the right and bottom margins.
See also marginsRemoved().
QRectF QRectF::marginsRemoved(const QMarginsF &m) const
Returns a rectangle shrunk by the margins m.
See also marginsAdded().
void QRectF::moveBottom(double p)
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given p. The rectangle's size is unchanged.
See also bottom() and moveTop().
void QRectF::moveBottomLeft(const QPointF &p)
Moves the rectangle so that its bottom-left corner is at p, keeping its size.
void QRectF::moveBottomRight(const QPointF &p)
Moves the rectangle so that its bottom-right corner is at p, keeping its size.
void QRectF::moveCenter(const QPointF &p)
Moves the rectangle, leaving the center point at the given position p. The rectangle's size is unchanged.
See also center().
void QRectF::moveLeft(double p)
Moves the rectangle horizontally, leaving the rectangle's left edge at the given p. The rectangle's size is unchanged.
See also left() and moveRight().
void QRectF::moveRight(double p)
Moves the rectangle horizontally, leaving the rectangle's right edge at the given p. The rectangle's size is unchanged.
See also right() and moveLeft().
void QRectF::moveTo(double x, double y)
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.
See also translate().
void QRectF::moveTo(const QPointF &p)
This is an overloaded function.
Moves the rectangle, leaving the top-left corner at the given position p.
void QRectF::moveTop(double p)
Moves the rectangle vertically, leaving the rectangle's top edge at the given p. The rectangle's size is unchanged.
See also top() and moveBottom().
void QRectF::moveTopLeft(const QPointF &p)
Moves the rectangle so that its top-left corner is at p, keeping its size.
void QRectF::moveTopRight(const QPointF &p)
Moves the rectangle so that its top-right corner is at p, keeping its size.
QRectF QRectF::normalized() const
Returns a normalized rectangle, that is, one that has a non-negative width and height. If the width or height is negative, the rectangle is moved so that it covers the same area with a positive extent.
See also isValid().
QRectF QRectF::operator&(const QRectF &o) const
Returns the intersection of this rectangle and the rectangle o. Equivalent to intersected().
QRectF & QRectF::operator&=(const QRectF &o)
Sets this rectangle to its intersection with the rectangle o, and returns a reference to this rectangle.
QRectF & QRectF::operator+=(const QMarginsF &m)
Adds the margins m to this rectangle, as marginsAdded() does, and returns a reference to this rectangle.
QRectF & QRectF::operator-=(const QMarginsF &m)
Removes the margins m from this rectangle, as marginsRemoved() does, and returns a reference to this rectangle.
QRectF QRectF::operator|(const QRectF &o) const
Returns the bounding rectangle of this rectangle and the rectangle o. Equivalent to united().
QRectF & QRectF::operator|=(const QRectF &o)
Sets this rectangle to the bounding rectangle of itself and the rectangle o, and returns a reference to this rectangle.
double QRectF::right() const
Returns the x coordinate of the rectangle's right edge, which is left() + width().
See also setRight() and left().
void QRectF::setBottom(double v)
Sets the bottom edge of the rectangle to v, leaving the top edge unchanged and so changing the height.
See also bottom() and moveBottom().
void QRectF::setBottomLeft(const QPointF &p)
Sets the bottom-left corner to p, keeping the top-right corner.
See also bottomLeft() and moveBottomLeft().
void QRectF::setBottomRight(const QPointF &p)
Sets the bottom-right corner to p, keeping the top-left corner.
See also bottomRight() and moveBottomRight().
void QRectF::setCoords(double xa, double ya, double xb, double yb)
Sets the coordinates of the rectangle's top-left corner to (xa, ya), and of its bottom-right corner to (xb, yb).
See also setRect().
void QRectF::setHeight(double v)
Sets the height of the rectangle to v, keeping the top edge.
See also height() and setWidth().
void QRectF::setLeft(double v)
Sets the left edge of the rectangle to v, leaving the right edge unchanged and so changing the width.
See also left() and moveLeft().
void QRectF::setRect(double x, double y, double wd, double ht)
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given wd and ht.
See also setCoords().
void QRectF::setRight(double v)
Sets the right edge of the rectangle to v, leaving the left edge unchanged and so changing the width.
See also right() and moveRight().
void QRectF::setSize(const QSizeF &s)
Sets the size of the rectangle to s, keeping the top-left corner.
See also size().
void QRectF::setTop(double v)
Sets the top edge of the rectangle to v, leaving the bottom edge unchanged and so changing the height.
void QRectF::setTopLeft(const QPointF &p)
Sets the top-left corner to p, keeping the bottom-right corner.
See also topLeft() and moveTopLeft().
void QRectF::setTopRight(const QPointF &p)
Sets the top-right corner to p, keeping the bottom-left corner.
See also topRight() and moveTopRight().
void QRectF::setWidth(double v)
Sets the width of the rectangle to v, keeping the left edge.
See also width() and setHeight().
void QRectF::setX(double v)
Sets the left edge of the rectangle to v, leaving the right edge unchanged and so changing the width. Equivalent to setLeft().
void QRectF::setY(double v)
Sets the top edge of the rectangle to v, leaving the bottom edge unchanged and so changing the height. Equivalent to setTop().
QSizeF QRectF::size() const
Returns the size of the rectangle.
See also setSize(), width() and height().
QRect QRectF::toAlignedRect() const
Returns the smallest QRect that contains this rectangle, rounding the left and top edges down and the right and bottom edges up.
See also toRect().
double QRectF::top() const
Returns the y coordinate of the rectangle's top edge. Equivalent to y().
See also setTop() and bottom().
QPointF QRectF::topLeft() const
Returns the position of the rectangle's top-left corner.
See also bottomRight().
QPointF QRectF::topRight() const
Returns the position of the rectangle's top-right corner.
See also bottomLeft().
QRect QRectF::toRect() const
Returns a QRect with the coordinates of the top-left and bottom-right corners each rounded to the nearest integer.
See also toAlignedRect() and QRectF(const QRect &).
void QRectF::translate(double dx, double dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
See also translated() and moveTo().
void QRectF::translate(const QPointF &p)
This is an overloaded function.
Moves the rectangle by the offset p, relative to the current position.
QRectF QRectF::translated(double dx, double dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis.
See also translate().
QRectF QRectF::translated(const QPointF &p) const
This is an overloaded function.
Returns a copy of the rectangle that is translated by the offset p.
QRectF QRectF::transposed() const
Returns a copy of the rectangle with its width and height exchanged, keeping the top-left corner.
See also QSizeF::transposed().
QRectF QRectF::united(const QRectF &o) const
Returns the bounding rectangle of this rectangle and the rectangle o. If one of the rectangles is null, the other is returned.
See also intersected().
double QRectF::width() const
Returns the width of the rectangle.
See also setWidth() and height().
double QRectF::x() const
Returns the x coordinate of the rectangle's left edge. Equivalent to left().
double QRectF::y() const
Returns the y coordinate of the rectangle's top edge. Equivalent to top().