QRect Class Reference |
One pixel wide pen | Two pixel wide pen | Three pixel wide pen |
For historical reasons right() and bottom() deviate from the true bottom-right corner of the rectangle. The right() function returns left() + width() + 1 and the bottom() function returns top() + height() + 1. The bottom-right green point in the diagrams above shows the return coordinates of these functions. We recommend that you use x() + width() and y() + height() to find the bottom-right corner, and avoid right() and bottom().
Another solution is to use QRectF: The QRectF class defines a rectangle in the plane using floating point coordinates for accuracy (QRect uses integer coordinates), and the QRectF::right() and QRectF::bottom() functions do return the true bottom-right corner.
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 three identical rectangles.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16)); QRect r3(QPoint(100, 200), QPoint(110, 215)); // not recommended
The third constructor creates a QRect using the top-left and bottom-right coordinates, but we recommend that you avoid using it, since it often doesn't do what you want (as explained above).
After creation the dimensions can be changed, e.g. with setLeft(), setRight(), setTop() and setBottom(), or by setting sizes, e.g. setWidth(), setHeight() and setSize(). The dimensions can also be changed with the move functions, e.g. translate(), moveCenter(), moveBottomRight(), etc. You can also add coordinates to a rectangle with adjust(). You can get a new rectangle based on adjustments from the original rectangled with adjusted(). You can test to see if a QRect contains a specific point with contains().
You can also test to see if two QRects intersect with intersects(), or retrieve the intersection as a QRect using intersect():
To retrieve the bounding rectangle of two QRects use unite():
See also QPoint, QSize, QPolygon, and QRectF.
Constructs a null rectangle.
See also isNull().
Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.
Constructs a rectangle with topLeft as the top-left corner and size as the rectangle size.
Constructs a rectangle with the top, left corner and width and height.
Adds xp1, yp1, xp2 and yp2 respectively to the existing coordinates of the rectangle.
See also adjusted().
Returns a new rectangle with xp1, yp1, xp2 and yp2 added to the existing coordinates of this rectangle.
See also adjust().
Returns the bottom coordinate of the rectangle.
See also setBottom(), top(), bottomLeft(), and bottomRight().
Returns the bottom-left position of the rectangle.
See also setBottomLeft(), moveBottomLeft(), topRight(), bottom(), and left().
Returns the bottom-right position of the rectangle.
See also setBottomRight(), moveBottomRight(), topLeft(), right(), and bottom().
Returns the center point of the rectangle.
See also moveCenter(), topLeft(), bottomRight(), topRight(), and bottomLeft().
Returns true if the point p is inside or on the edge of the rectangle; otherwise returns false.
If proper is true, this function returns true only if p is inside (not on the edge).
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if the point x, y is inside this rectangle; otherwise returns false.
If proper is true, this function returns true only if the point is entirely inside (not on the edge).
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if the point x, y is inside this rectangle; otherwise returns false.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if the rectangle r is inside this rectangle; otherwise returns false.
If proper is true, this function returns true only if r is entirely inside (not on the edge).
See also unite(), intersect(), and intersects().
Extracts the rectangle parameters as the top-left point *xp1, *yp1 and the bottom-right point *xp2, *yp2.
See also setCoords() and getRect().
Extracts the rectangle parameters as the position *x, *y and width *w and height *h.
See also setRect() and getCoords().
Returns the height of the rectangle. The height includes both the top and bottom edges, i.e. height = bottom - top + 1.
See also width(), size(), and setHeight().
Returns the intersection of this rectangle and rectangle r. r.intersect(s) is equivalent to r&s.
Returns true if this rectangle intersects with rectangle r (there is at least one pixel that is within both rectangles); otherwise returns false.
See also intersect() and contains().
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. isEmpty() == !isValid()
See also isNull(), isValid(), and normalized().
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, that is right() == left() - 1 and bottom() == top() - 1.
Note that if right() == left() and bottom() == top(), then the rectangle has width 1 and height 1.
A null rectangle is also empty.
A null rectangle is not valid.
See also isEmpty() and isValid().
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.
isValid() == !isEmpty()
See also isNull(), isEmpty(), and normalized().
Returns the left coordinate of the rectangle. Identical to x().
See also setLeft(), right(), topLeft(), and bottomLeft().
Sets the bottom position of the rectangle to pos, leaving the size unchanged.
See also bottom(), setBottom(), moveLeft(), moveTop(), and moveRight().
Sets the bottom-left position of the rectangle to p, leaving the size unchanged.
See also bottomLeft(), setBottomLeft(), moveTopLeft(), moveBottomRight(), and moveTopRight().
Sets the bottom-right position of the rectangle to p, leaving the size unchanged.
See also bottomRight(), setBottomRight(), moveTopLeft(), moveTopRight(), and moveBottomLeft().
Sets the center point of the rectangle to p, leaving the size unchanged.
See also center(), moveTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().
Sets the left position of the rectangle to pos, leaving the size unchanged.
See also left(), setLeft(), moveTop(), moveRight(), and moveBottom().
Sets the right position of the rectangle to pos, leaving the size unchanged.
See also right(), setRight(), moveLeft(), moveTop(), and moveBottom().
Moves the top left corner of the rectangle to x and y, without changing the rectangles size.
See also translate() and moveTopLeft().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Moves the top left corner of the rectangle to pt, without changing the rectangles size.
See also translate() and moveTopLeft().
Sets the top position of the rectangle to pos, leaving the size unchanged.
See also top(), setTop(), moveLeft(), moveRight(), and moveBottom().
Sets the top-left position of the rectangle to p, leaving the size unchanged.
See also topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().
Sets the top-right position of the rectangle to p, leaving the size unchanged.
See also topRight(), setTopRight(), moveTopLeft(), moveBottomRight(), and moveBottomLeft().
Returns a normalized rectangle, i.e. a rectangle that has a non-negative width and height.
It swaps left and right if left() > right(), and swaps top and bottom if top() > bottom().
See also isValid().
Returns the right coordinate of the rectangle.
See also setRight(), left(), topRight(), and bottomRight().
Sets the bottom edge of the rectangle to pos. May change the height, but will never change the top edge of the rectangle.
See also bottom(), setTop(), and setHeight().
Set the bottom-left corner of the rectangle to p. May change the size, but will the never change the top-right corner of the rectangle.
See also bottomLeft(), moveBottomLeft(), setTopLeft(), setBottomRight(), and setTopRight().
Set the bottom-right corner of the rectangle to p. May change the size, but will the never change the top-left corner of the rectangle.
See also bottomRight(), moveBottomRight(), setTopLeft(), setTopRight(), and setBottomLeft().
Sets the coordinates of the rectangle's top-left corner to (xp1, yp1), and the coordinates of its bottom-right corner to (xp2, yp2).
See also coords(), getCoords(), and setRect().
Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.
See also height(), setTop(), setBottom(), and setSize().
Sets the left edge of the rectangle to pos. May change the width, but will never change the right edge of the rectangle.
Identical to setX().
See also left(), setTop(), and setWidth().
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to (w, h).
See also rect(), getRect(), and setCoords().
Sets the right edge of the rectangle to pos. May change the width, but will never change the left edge of the rectangle.
See also right(), setLeft(), and setWidth().
Sets the size of the rectangle to s. The top-left corner is not moved.
See also size(), setWidth(), and setHeight().
Sets the top edge of the rectangle to pos. May change the height, but will never change the bottom edge of the rectangle.
Identical to setY().
See also top(), setBottom(), and setHeight().
Set the top-left corner of the rectangle to p. May change the size, but will the never change the bottom-right corner of the rectangle.
See also topLeft(), moveTopLeft(), setBottomRight(), setTopRight(), and setBottomLeft().
Set the top-right corner of the rectangle to p. May change the size, but will the never change the bottom-left corner of the rectangle.
See also topRight(), moveTopRight(), setTopLeft(), setBottomRight(), and setBottomLeft().
Sets the width of the rectangle to w. The right edge is changed, but not the left edge.
See also width(), setLeft(), setRight(), and setSize().
Sets the x position of the rectangle (its left end) to x. May change the width, but will never change the right edge of the rectangle.
Identical to setLeft().
Sets the y position of the rectangle (its top) to y. May change the height, but will never change the bottom edge of the rectangle.
Identical to setTop().
Returns the size of the rectangle.
See also setSize(), width(), and height().
Returns the top coordinate of the rectangle. Identical to y().
See also setTop(), bottom(), topLeft(), and topRight().
Returns the top-left position of the rectangle.
See also setTopLeft(), moveTopLeft(), bottomRight(), left(), and top().
Returns the top-right position of the rectangle.
See also setTopRight(), moveTopRight(), bottomLeft(), top(), and right().
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(), and translated().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Moves the rectangle p.x() along the x axis and p.y() along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
See also moveTopLeft().
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().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns a copy of the rectangle that is translated p.x() along the x axis and p.y() along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
See also translate().
Returns the bounding rectangle of this rectangle and rectangle r. r.unite(s) is equivalent to r|s.
Returns the width of the rectangle.
See also setWidth(), height(), size(), and setHeight().
Returns the left coordinate of the rectangle. Identical to left().
See also left(), y(), and setX().
Returns the top coordinate of the rectangle. Identical to top().
See also top(), x(), and setY().
Returns the intersection of this rectangle and rectangle r.
Returns an empty rectangle if there is no intersection.
This is equivalent to calling
intersect(r)
.
See also operator&=(), operator|(), isEmpty(), intersect(), contains(), and unite().
Intersects this rectangle with rectangle r.
Returns the bounding rectangle of this rectangle and rectangle r.
This is the equivalent to calling
unite(r)
.
See also operator|=(), operator&(), intersect(), contains(), and unite().
Unites this rectangle with rectangle r.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if the rectangles r1 and r2 are different; otherwise returns false.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Writes the rectangle to the stream, and returns a reference to the stream.
See also Format of the QDataStream operators.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if the rectangles r1 and r2 are equal; otherwise returns false.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Reads a rectangle from the stream, and returns a reference to the stream.
See also Format of the QDataStream operators.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com