分类: C/C++
2010-07-08 13:49:15
[ module]
The QRect class defines a rectangle in the plane using integer precision.
#include
()
( const QPoint & topLeft, const QPoint & bottomRight )
( const QPoint & topLeft, const QSize & size )
( int x, int y, int width, int height )
void
( int dx1, int dy1, int dx2, int dy2 )
QRect
( int dx1, int dy1, int dx2, int dy2 ) const
int
() const
QPoint
() const
QPoint
() const
QPoint
() const
bool
( const QPoint & point, bool proper = false ) const
bool
( int x, int y, bool proper ) const
bool
( int x, int y ) const
bool
( const QRect & rectangle, bool proper = false ) const
void
( int * x1, int * y1, int * x2, int * y2 ) const
void
( int * x, int * y, int * width, int * height ) const
int
() const
QRect
( const QRect & rectangle ) const
bool
( const QRect & rectangle ) const
bool
() const
bool
() const
bool
() const
int
() const
void
( int y )
void
( const QPoint & position )
void
( const QPoint & position )
void
( const QPoint & position )
void
( int x )
void
( int x )
void
( int x, int y )
void
( const QPoint & position )
void
( int y )
void
( const QPoint & position )
void
( const QPoint & position )
QRect
() const
int
() const
void
( int y )
void
( const QPoint & position )
void
( const QPoint & position )
void
( int x1, int y1, int x2, int y2 )
void
( int height )
void
( int x )
void
( int x, int y, int width, int height )
void
( int x )
void
( const QSize & size )
void
( int y )
void
( const QPoint & position )
void
( const QPoint & position )
void
( int width )
void
( int x )
void
( int y )
QSize
() const
int
() const
QPoint
() const
QPoint
() const
void
( int dx, int dy )
void
( const QPoint & offset )
QRect
( int dx, int dy ) const
QRect
( const QPoint & offset ) const
QRect
( const QRect & rectangle ) const
int
() const
int
() const
int
() const
QRect
( const QRect & rectangle ) const
QRect &
( const QRect & rectangle )
QRect
( const QRect & rectangle ) const
QRect &
( const QRect & rectangle )
bool
( const QRect & r1, const QRect & r2 )
QDataStream &
( QDataStream & stream, const QRect & rectangle )
bool
( const QRect & r1, const QRect & r2 )
QDataStream &
( QDataStream & stream, QRect & rectangle )
The QRect class defines a rectangle in the plane using integer precision.
A rectangle is normally expressed as an upper-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 and a . The following code creates two identical rectangles.
QRect r1(100, 200, 11, 16); QRect r2(QPoint(100, 200), QSize(11, 16));
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 () and () 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 provide functions to move the rectangle relative to the various coordinates. In addition there is a () function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, the () function moves the rectangle the given offset relative to the current position, and the () function returns a translated copy of this rectangle.
The () function returns the rectange's dimensions as a . The dimensions can also be retrieved separately using the() and () functions. To manipulate the dimensions use the (), () or () functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example, () or().
The () function tells whether a given point is inside the rectangle or not, and the () function returns true if this rectangle intersects with a given rectangle. The QRect class also provides the () function which returns the intersection rectangle, and the () function which returns the rectangle that encloses the given rectangle and this:
() ()
The () function returns true if () > () or () > (). Note that an empty rectangle is not valid: The () function returns true if () <= () and () <= (). A null rectangle (() == true) on the other hand, has both width and height set to 0.
Note that due to the way QRect and are defined, an empty QRect is defined in essentially the same way as .
Finally, QRect objects can be streamed as well as compared.
When using an painter, the boundary line of a QRect 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 QRect'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 QRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRect also provide functions to move the rectangle relative to the various coordinates.
For example the (), () and () functions as an example: () returns the x-coordinate of the rectangle's left edge, () sets the left edge of the rectangle to the given x coordinate (it may change the width, but will never change the rectangle's right edge) and () moves the entire rectangle horizontally, leaving the rectangle's left edge at the given x coordinate and its size unchanged.
Note that for historical reasons the values returned by the () and () functions deviate from the true bottom-right corner of the rectangle: The () function returns () + () - 1 and the () function returns () + () - 1. The same is the case for the point returned by the () convenience function. In addition, the x and y coordinate of the () and () functions, respectively, contain the same deviation from the true right and bottom edges.
We recommend that you use () + () and () + () to find the true bottom-right corner, and avoid () and (). Another solution is to use : The class defines a rectangle in the plane using floating point accuracy for coordinates, and the () and () functions do return the right and bottom coordinates.
It is also possible to add offsets to this rectangle's coordinates using the () function, as well as retrieve a new rectangle based on adjustments of the original one using the () function. If either of the width and height is negative, use the() function toretrieve a rectangle where the corners are swapped.
In addition, QRect provides the () function which extracts the position of the rectangle's top-left and bottom-right corner, and the () function which extracts the rectangle's top-left corner, width and height. Use the () and() function to manipulate the rectangle's coordinates and dimensions in one go.
See also and .
Constructs a null rectangle.
See also ().
Constructs a rectangle with the given topLeft and bottomRight corners.
See also () and ().
Constructs a rectangle with the given topLeft corner and the given size.
See also () and ().
Constructs a rectangle with (x, y) as its top-left corner and the given width and height.
See also ().
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
See also () and ().
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle.
See also ().
Returns the y-coordinate of the rectangle's bottom edge.
Note that for historical reasons this function returns () + () - 1; use () + () to retrieve the true y-coordinate.
See also (), (), and ().
Returns the position of the rectangle's bottom-left corner. Note that for historical reasons this function returns ((), () + () - 1).
See also (), (), and ().
Returns the position of the rectangle's bottom-right corner.
Note that for historical reasons this function returns (() + () -1, () + () - 1).
See also (), (), and ().
Returns the center point of the rectangle.
See also ().
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).
See also ().
This is an overloaded function.
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).
This is an overloaded function.
Returns true if the point (x, y) is inside this rectangle, otherwise returns false.
This is an overloaded function.
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).
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.
See also () and ().
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.
See also () and ().
Returns the height of the rectangle.
See also (), (), and ().
Returns the intersection of this rectangle and the given rectangle. Note that r.intersected(s) is equivalent to r & s.
This function was introduced in Qt 4.2.
See also (), (), and ().
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 () function.
See also ().
Returns true if the rectangle is empty, otherwise returns false.
An empty rectangle has a () > () or () > (). An empty rectangle is not valid (i.e., isEmpty() == !()).
Use the () function to retrieve a rectangle where the corners are swapped.
See also (), (), and ().
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 (i.e., () == () - 1 and () == () - 1). A null rectangle is also empty, and hence is not valid.
See also () and ().
Returns true if the rectangle is valid, otherwise returns false.
A valid rectangle has a () < () and () < (). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !()).
See also (), (), and ().
Returns the x-coordinate of the rectangle's left edge. Equivalent to ().
See also (), (), and ().
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the bottom-left corner at the given position. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the bottom-right corner at the given position. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged.
See also ().
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.
See also () and ().
Moves the rectangle, leaving the top-left corner at the given position.
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the top-left corner at the given position. The rectangle's size is unchanged.
See also (), (), and ().
Moves the rectangle, leaving the top-right corner at the given position. The rectangle's size is unchanged.
See also (), (), and ().
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.
If () < 0 the function swaps the left and right corners, and it swaps the top and bottom corners if () < 0.
See also () and ().
Returns the x-coordinate of the rectangle's right edge.
Note that for historical reasons this function returns () + () - 1; use () + () to retrieve the true x-coordinate.
See also (), (), and ().
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.
See also () and ().
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.
See also () and ().
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.
See also () and ().
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2).
See also (), (), and ().
Sets the height of the rectangle to the given height. The bottom edge is changed, but not the top one.
See also () and ().
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 ().
See also () and ().
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width and height.
See also (), (), and ().
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.
See also () and ().
Sets the size of the rectangle to the given size. The top-left corner is not moved.
See also (), (), and ().
Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.
Equivalent to ().
See also () and ().
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.
See also () and ().
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.
See also () and ().
Sets the width of the rectangle to the given width. The right edge is changed, but not the left one.
See also () and ().
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 ().
See also (), (), and ().
Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.
Equivalent to ().
See also (), (), and ().
Returns the size of the rectangle.
See also (), (), and ().
Returns the y-coordinate of the rectangle's top edge. Equivalent to ().
See also (), (), and ().
Returns the position of the rectangle's top-left corner.
See also (), (), and ().
Returns the position of the rectangle's top-right corner.
Note that for historical reasons this function returns (() + () -1, ()).
See also (), (), and ().
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 (), (), and ().
This is an overloaded function.
Moves the rectangle offset. along the x axis and offset. 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.
See also ().
This is an overloaded function.
Returns a copy of the rectangle that is translated offset. along the x axis and offset. along the y axis, relative to the current position.
Returns the bounding rectangle of this rectangle and the given rectangle.
This function was introduced in Qt 4.2.
See also ().
Returns the width of the rectangle.
See also (), (), and ().
Returns the x-coordinate of the rectangle's left edge. Equivalent to ().
See also (), (), and ().
Returns the y-coordinate of the rectangle's top edge. Equivalent to ().
See also (), (), and ().
Returns the intersection of this rectangle and the given rectangle. Returns an empty rectangle if there is no intersection.
See also () and ().
Intersects this rectangle with the given rectangle.
See also () and ().
Returns the bounding rectangle of this rectangle and the given rectangle.
See also () and ().
Unites this rectangle with the given rectangle.
See also () and ().
Returns true if the rectangles r1 and r2 are different, otherwise returns false.
Writes the given rectangle to the given stream, and returns a reference to the stream.
See also .
Returns true if the rectangles r1 and r2 are equal, otherwise returns false.
Reads a rectangle from the given stream into the given rectangle, and returns a reference to the stream.
See also .