CopperSpice API
1.9.2
|
The QRectF class defines a rectangle in the plane using floating point precision. More...
Public Methods | |
QRectF () | |
QRectF (const QPointF &topLeft, const QPointF &bottomRight) | |
QRectF (const QPointF &topLeft, const QSizeF &size) | |
QRectF (const QRect &rect) | |
QRectF (qreal left, qreal top, qreal width, qreal height) | |
void | adjust (qreal x1, qreal y1, qreal x2, qreal y2) |
QRectF | adjusted (qreal x1, qreal y1, qreal x2, qreal y2) const |
qreal | bottom () const |
QPointF | bottomLeft () const |
QPointF | bottomRight () const |
QPointF | center () const |
bool | contains (const QPointF &point) const |
bool | contains (const QRectF &rect) const |
bool | contains (qreal x, qreal y) const |
void | getCoords (qreal *x1, qreal *y1, qreal *x2, qreal *y2) const |
void | getRect (qreal *x, qreal *y, qreal *width, qreal *height) const |
qreal | height () const |
QRectF | intersected (const QRectF &rect) const |
bool | intersects (const QRectF &rect) const |
bool | isEmpty () const |
bool | isNull () const |
bool | isValid () const |
qreal | left () const |
QRectF | marginsAdded (const QMarginsF &margins) const |
QRectF | marginsRemoved (const QMarginsF &margins) const |
void | moveBottom (qreal pos) |
void | moveBottomLeft (const QPointF &point) |
void | moveBottomRight (const QPointF &point) |
void | moveCenter (const QPointF &point) |
void | moveLeft (qreal pos) |
void | moveRight (qreal pos) |
void | moveTo (const QPointF &point) |
void | moveTo (qreal x, qreal y) |
void | moveTop (qreal pos) |
void | moveTopLeft (const QPointF &point) |
void | moveTopRight (const QPointF &point) |
QRectF | normalized () const |
QRectF | operator& (const QRectF &rect) const |
QRectF & | operator&= (const QRectF &rect) |
QRectF & | operator+= (const QMarginsF &margins) |
QRectF & | operator-= (const QMarginsF &margins) |
QRectF | operator| (const QRectF &rect) const |
QRectF & | operator|= (const QRectF &rect) |
qreal | right () const |
void | setBottom (qreal pos) |
void | setBottomLeft (const QPointF &point) |
void | setBottomRight (const QPointF &point) |
void | setCoords (qreal x1, qreal y1, qreal x2, qreal y2) |
void | setHeight (qreal h) |
void | setLeft (qreal pos) |
void | setRect (qreal x, qreal y, qreal width, qreal height) |
void | setRight (qreal pos) |
void | setSize (const QSizeF &size) |
void | setTop (qreal pos) |
void | setTopLeft (const QPointF &point) |
void | setTopRight (const QPointF &point) |
void | setWidth (qreal w) |
void | setX (qreal xPos) |
void | setY (qreal yPos) |
QSizeF | size () const |
QRect | toAlignedRect () const |
qreal | top () const |
QPointF | topLeft () const |
QPointF | topRight () const |
QRect | toRect () const |
void | translate (const QPointF &offset) |
void | translate (qreal x, qreal y) |
QRectF | translated (const QPointF &offset) const |
QRectF | translated (qreal x, qreal y) const |
QRectF | united (const QRectF &rect) const |
qreal | width () const |
qreal | x () const |
qreal | y () const |
Friends | |
bool | operator!= (const QRectF &rect1, const QRectF &rect2) |
bool | operator== (const QRectF &rect1, const QRectF &rect2) |
Related Functions | |
These are not member functions | |
QDataStream & | operator<< (QDataStream &stream, const QRectF &rectF) |
QDataStream & | operator>> (QDataStream &stream, QRectF &rectF) |
The QRectF class defines a rectangle in the plane using floating point precision. A rectangle is normally expressed as an upper-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 integers, or from a QPoint and a QSize. The following code creates two identical rectangles.
There is also a third constructor which creates a QRectF from a QRect and a corresponding toRect() method which returns a QRect object based on the values of this rectangle. 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 provide 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 rectangles 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() method 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() method which returns the intersection rectangle, and the united() function which returns the rectangle that encloses the given rectangle.
intersected() | united() |
The isEmpty() method returns true if the rectangle's width or height is less than or equal to, 0. An empty rectangle is not valid. The isValid() method returns true if both width and height is larger than 0. A null rectangle has both width and height set to 0. An empty QRectF is defined in essentially the same way as QRect. QRectF objects can be streamed as well as compared.
When using an anti-aliased painter, the boundary line of a QRectF will be rendered symmetrically on both sides of the mathematical rectangle's boundary line. But when using an aliased painter (the default) other rules apply.
Then, when rendering with a one pixel wide pen the QRectF's boundary line will be rendered to the right and below the mathematical rectangle's boundary line.
When rendering with a two pixels wide pen the boundary line will be split in the middle by the mathematical rectangle. This will be the case whenever the pen is set to an even number of pixels, while rendering with a pen with an odd number of pixels, the spare pixel will be rendered to the right and below the mathematical rectangle as in the one pixel case.
Logical representation | One pixel wide pen |
Two pixel wide pen | Three pixel wide pen |
The QRectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRectF also provide functions to move the rectangle relative to the various coordinates.
For example: the bottom(), setBottom() and moveBottom() functions: bottom() returns the y-coordinate of the rectangle's bottom edge, setBottom() sets the bottom edge of the rectangle to the given y coordinate (it may change the height, but will never change the rectangle's top edge) and moveBottom() moves the entire rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate and its size unchanged.
It is also possible to add offsets to this rectangle's coordinates using the adjust() function, as well as retrieve a new rectangle based on adjustments of the original one using the adjusted() function. If either of the width and height is negative, use the normalized() function to retrieve a rectangle where the corners are swapped.
In addition, QRectF provides the getCoords() function which extracts the position of the rectangle's top-left and bottom-right corner, and the getRect() function which extracts the rectangle's top-left corner, width and height. Use the setCoords() and setRect() function to manipulate the rectangle's coordinates and dimensions in one go.
|
inline |
Constructs a null rectangle.
Constructs a rectangle with the given topLeft corner and the given size.
Constructs a rectangle with the given topLeft and bottomRight corners.
Constructs a rectangle with (left, top) as its top-left corner and the given width and height.
|
inline |
Adds x1, y1, x2 and y2 respectively to the existing coordinates of the rectangle.
Returns a new rectangle with x1, y1, x2 and y2 added respectively to the existing coordinates of this rectangle.
|
inline |
Returns the y-coordinate of the rectangle's bottom edge.
|
inline |
Returns the position of the rectangle's bottom-left corner.
|
inline |
Returns the position of the rectangle's bottom-right corner.
|
inline |
Returns the center point of the rectangle.
bool QRectF::contains | ( | const QPointF & | point | ) | const |
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false.
bool QRectF::contains | ( | const QRectF & | rect | ) | const |
Returns true if the given rect is inside this rectangle, otherwise returns false.
Returns true if the point (x, y) is inside or on the edge of the rectangle, otherwise returns false.
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.
Extracts the position of the rectangle's top-left corner to x and y, and its dimensions to width and height.
|
inline |
Returns the height of the rectangle.
|
inline |
Returns the intersection of this rectangle and the given rect. Calling a.intersected(b)
is equivalent to a & b
.
bool QRectF::intersects | ( | const QRectF & | rect | ) | const |
Returns true if this rectangle intersects with the given rect. This means there is a non-empty area of overlap between them. The intersection rectangle can be retrieved using intersected().
|
inline |
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.
|
inline |
|
inline |
Returns true if the rectangle is valid, otherwise returns false. A valid rectangle has a width() > 0 and height() > 0. Non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).
|
inline |
Returns the x-coordinate of the rectangle's left edge. Equivalent to x().
|
inline |
Returns a new rectangle grown by margins.
|
inline |
Returns a new rectangle shrunk by margins
|
inline |
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given pos coordinate. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the bottom-left corner at the given point. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the bottom-right corner at the given point. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the center point at the given point. The rectangle's size is unchanged.
|
inline |
Moves the rectangle horizontally, leaving the rectangle's left edge at the given pos coordinate. The rectangle's size is unchanged.
|
inline |
Moves the rectangle horizontally, leaving the rectangle's right edge at the given pos coordinate. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the top-left corner at the given point.
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.
|
inline |
Moves the rectangle vertically, leaving the rectangle's top line at the given pos coordinate. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the top-left corner at the given point. The rectangle's size is unchanged.
|
inline |
Moves the rectangle, leaving the top-right corner at the given point. The rectangle's size is unchanged.
QRectF QRectF::normalized | ( | ) | const |
QRectF QRectF::operator& | ( | const QRectF & | rect | ) | const |
Returns the intersection of this rectangle and the given rect. Returns an empty rectangle if there is no intersection.
|
inline |
Intersects this rectangle with the given rect.
|
inline |
Grows this rectangle by margins.
|
inline |
Shrinks this rectangle by margins.
QRectF QRectF::operator| | ( | const QRectF & | rect | ) | const |
Returns the bounding rectangle of this rectangle and the given rect.
|
inline |
Unites this rectangle with the given rect.
|
inline |
Returns the x-coordinate of the rectangle's right edge.
|
inline |
Sets the bottom edge of the rectangle to the given pos coordinate. May change the height, but will never change the top edge of the rectangle.
|
inline |
Set the bottom-left corner of the rectangle to the given point. May change the size, but will never change the top-right corner of the rectangle.
|
inline |
Set the bottom-right corner of the rectangle to the given point. 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).
|
inline |
|
inline |
Sets the left edge of the rectangle to the given pos coordinate. May change the width, but will never change the right edge of the rectangle.
Equivalent to setX().
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width and height.
|
inline |
Sets the right edge of the rectangle to the given pos coordinate. May change the width, but will never change the left edge of the rectangle.
|
inline |
Sets the size of the rectangle to the given size. The top-left corner is not moved.
|
inline |
|
inline |
Set the top-left corner of the rectangle to the given point. May change the size, but will never change the bottom-right corner of the rectangle.
|
inline |
Set the top-right corner of the rectangle to the given point. May change the size, but will never change the bottom-left corner of the rectangle.
|
inline |
|
inline |
Sets the left edge of the rectangle to the given xPos coordinate. May change the width, but will never change the right edge of the rectangle.
Equivalent to setLeft().
|
inline |
Sets the top edge of the rectangle to the given yPos coordinate. May change the height, but will never change the bottom edge of the rectangle.
Equivalent to setTop().
|
inline |
QRect QRectF::toAlignedRect | ( | ) | const |
|
inline |
Returns the y-coordinate of the rectangle's top edge. Equivalent to y().
|
inline |
Returns the position of the rectangle's top-left corner.
|
inline |
Returns the position of the rectangle's top-right corner.
|
inline |
Returns a QRect based on the values of this rectangle. The coordinates in the returned rectangle are rounded to the nearest integer.
|
inline |
Moves the rectangle offset.x() along the x axis and offset.y() along the y axis, relative to the current position.
Moves the rectangle x along the x-axis and y along the y-axis, relative to the current position. Positive values move the rectangle to the right and downwards.
|
inline |
Returns a copy of the rectangle that is translated offset.x() along the x axis and offset.y() along the y axis, relative to the current position.
Returns a copy of the rectangle that is translated x along the x axis and y along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
|
inline |
|
inline |
Returns the width of the rectangle.
|
inline |
|
inline |
|
friend |
Returns true if the rectangles rect1 and rect2 are different, otherwise returns false.
|
related |
Writes the given rectF to the stream. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.
|
friend |
Returns true if the rectangles rect1 and rect2 are equal, otherwise returns false.
|
related |
Reads from the stream into the given rectF. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.