NAME
QRect - Defines a rectangle in the plane
SYNOPSIS
#include <
qrect.h>
Public Members
<li class=fn>
QRect () <li class=fn>
QRect ( const QPoint & topLeft, const QPoint & bottomRight ) <li class=fn>
QRect ( const QPoint & topLeft, const QSize & size ) <li class=fn>
QRect ( int left, int top, int width, int height ) <li class=fn>bool
isNull () const <li class=fn>bool
isEmpty () const <li class=fn>bool
isValid () const <li class=fn>QRect
normalize () const <li class=fn>int
left () const <li class=fn>int
top () const <li class=fn>int
right () const <li class=fn>int
bottom () const <li class=fn>QCOORD &
rLeft () <li class=fn>QCOORD &
rTop () <li class=fn>QCOORD &
rRight () <li class=fn>QCOORD &
rBottom () <li class=fn>int
x () const <li class=fn>int
y () const <li class=fn>void
setLeft ( int pos ) <li class=fn>void
setTop ( int pos ) <li class=fn>void
setRight ( int pos ) <li class=fn>void
setBottom ( int pos ) <li class=fn>void
setX ( int x ) <li class=fn>void
setY ( int y ) <li class=fn>void
setTopLeft ( const QPoint & p ) <li class=fn>void
setBottomRight ( const QPoint & p ) <li class=fn>void
setTopRight ( const QPoint & p ) <li class=fn>void
setBottomLeft ( const QPoint & p ) <li class=fn>QPoint
topLeft () const <li class=fn>QPoint
bottomRight () const <li class=fn>QPoint
topRight () const <li class=fn>QPoint
bottomLeft () const <li class=fn>QPoint
center () const <li class=fn>void
rect ( int * x, int * y, int * w, int * h ) const <li class=fn>void
coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const <li class=fn>void
moveLeft ( int pos ) <li class=fn>void
moveTop ( int pos ) <li class=fn>void
moveRight ( int pos ) <li class=fn>void
moveBottom ( int pos ) <li class=fn>void
moveTopLeft ( const QPoint & p ) <li class=fn>void
moveBottomRight ( const QPoint & p ) <li class=fn>void
moveTopRight ( const QPoint & p ) <li class=fn>void
moveBottomLeft ( const QPoint & p ) <li class=fn>void
moveCenter ( const QPoint & p ) <li class=fn>void
moveBy ( int dx, int dy ) <li class=fn>void
setRect ( int x, int y, int w, int h ) <li class=fn>void
setCoords ( int xp1, int yp1, int xp2, int yp2 ) <li class=fn>void
addCoords ( int xp1, int yp1, int xp2, int yp2 ) <li class=fn>QSize
size () const <li class=fn>int
width () const <li class=fn>int
height () const <li class=fn>void
setWidth ( int w ) <li class=fn>void
setHeight ( int h ) <li class=fn>void
setSize ( const QSize & s ) <li class=fn>QRect
operator| ( const QRect & r ) const <li class=fn>QRect
operator& ( const QRect & r ) const <li class=fn>QRect &
operator|= ( const QRect & r ) <li class=fn>QRect &
operator&= ( const QRect & r ) <li class=fn>bool
contains ( const QPoint & p, bool proper = FALSE ) const <li class=fn>bool
contains ( int x, int y ) const <li class=fn>bool
contains ( int x, int y, bool proper ) const <li class=fn>bool
contains ( const QRect & r, bool proper = FALSE ) const <li class=fn>QRect
unite ( const QRect & r ) const <li class=fn>QRect
intersect ( const QRect & r ) const <li class=fn>bool
intersects ( const QRect & r ) const
RELATED FUNCTION DOCUMENTATION
<li class=fn>bool
operator== ( const QRect & r1, const QRect & r2 ) <li class=fn>bool
operator!= ( const QRect & r1, const QRect & r2 ) <li class=fn>QDataStream &
operator<< ( QDataStream & s, const QRect & r ) <li class=fn>QDataStream &
operator>> ( QDataStream & s, QRect & r )
DESCRIPTION
The QRect class defines a rectangle in the plane.
A rectangle is internally represented as an upper-left corner and a bottom-right corner, but it is normally expressed as an upper-left corner and a size.
The coordinate type is QCOORD (defined in qwindowdefs.h as int). The minimum value of QCOORD is QCOORD_MIN (-2147483648) and the maximum value is QCOORD_MAX (2147483647).
Note that the size (width and height) of a rectangle might be different from what you are used to. If the top-left corner and the bottom-right corner are the same, the height and the width of the rectangle will both be 1.
Generally, width = right - left + 1 and height = bottom - top + 1. We designed it this way to make it correspond to rectangular spaces used by drawing functions in which the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.
The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.
A QRect can be constructed with a set of left, top, width and height integers, from two QPoints or from a QPoint and a QSize. 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. moveBy(), moveCenter(), moveBottomRight(), etc. You can also add coordinates to a rectangle with addCoords().
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() (see also intersect()). To get the bounding rectangle of two QRects use unite().
See also QPoint, QSize, Graphics Classes, and Image Processing Classes.
MEMBER FUNCTION DOCUMENTATION
QRect::QRect ()
Constructs an invalid rectangle.
QRect::QRect ( const QPoint & topLeft, const QPoint & bottomRight )
Constructs a rectangle with
topLeft as the top-left corner and
bottomRight as the bottom-right corner.
QRect::QRect ( const QPoint & topLeft, const QSize & size )
Constructs a rectangle with
topLeft as the top-left corner and
size as the rectangle size.
QRect::QRect ( int left, int top, int width, int height )
Constructs a rectangle with the
top,
left corner and
width and
height.
Example (creates three identical rectangles):
QRect r1( QPoint(100,200), QPoint(110,215) );
QRect r2( QPoint(100,200), QSize(11,16) );
QRect r3( 100, 200, 11, 16 );
void QRect::addCoords ( int xp1, int yp1, int xp2, int yp2 )
Adds
xp1,
yp1,
xp2 and
yp2 respectively to the existing coordinates of the rectangle.
Examples:
int QRect::bottom () const
Returns the bottom coordinate of the rectangle.
See also setBottom(), top(), bottomLeft(), and bottomRight().
Examples:
QPoint QRect::bottomLeft () const
Returns the bottom-left position of the rectangle.
See also setBottomLeft(), moveBottomLeft(), topRight(), bottom(), and left().
Example: tictac/tictac.cpp.
QPoint QRect::bottomRight () const
Returns the bottom-right position of the rectangle.
See also setBottomRight(), moveBottomRight(), topLeft(), right(), and bottom().
Example: tictac/tictac.cpp.
QPoint QRect::center () const
Returns the center point of the rectangle.
See also moveCenter(), topLeft(), bottomRight(), topRight(), and bottomLeft().
Example: tooltip/tooltip.cpp.
bool QRect::contains ( const QPoint & p, bool proper = FALSE ) const
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).
Example: t14/cannon.cpp.
bool QRect::contains ( int x, int y ) const
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.
bool QRect::contains ( int x, int y, bool proper ) const
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).
bool QRect::contains ( const QRect & r, bool proper = FALSE ) const
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().
void QRect::coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const
Extracts the rectangle parameters as the top-left point
*xp1,
*yp1 and the bottom-right point
*xp2,
*yp2.
See also setCoords() and rect().
Examples:
int QRect::height () const
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().
Examples:
QRect QRect::intersect ( const QRect & r ) const
Returns the intersection of this rectangle and rectangle
r. r.intersect(s) is equivalent to r&s.
bool QRect::intersects ( const QRect & r ) const
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().
Examples:
bool QRect::isEmpty () const
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 normalize().
bool QRect::isNull () const
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().
bool QRect::isValid () const
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 normalize().
Examples:
int QRect::left () const
Returns the left coordinate of the rectangle. Identical to x().
See also setLeft(), right(), topLeft(), and bottomLeft().
Examples:
void QRect::moveBottom ( int pos )
Sets the bottom position of the rectangle to
pos, leaving the size unchanged.
See also bottom(), setBottom(), moveLeft(), moveTop(), and moveRight().
void QRect::moveBottomLeft ( const QPoint & p )
Sets the bottom-left position of the rectangle to
p, leaving the size unchanged.
See also bottomLeft(), setBottomLeft(), moveTopLeft(), moveBottomRight(), and moveTopRight().
Example: t10/cannon.cpp.
void QRect::moveBottomRight ( const QPoint & p )
Sets the bottom-right position of the rectangle to
p, leaving the size unchanged.
See also bottomRight(), setBottomRight(), moveTopLeft(), moveTopRight(), and moveBottomLeft().
void QRect::moveBy ( int dx, int dy )
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().
Examples:
void QRect::moveCenter ( const QPoint & p )
Sets the center point of the rectangle to
p, leaving the size unchanged.
See also center(), moveTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().
Examples:
void QRect::moveLeft ( int pos )
Sets the left position of the rectangle to
pos, leaving the size unchanged.
See also left(), setLeft(), moveTop(), moveRight(), and moveBottom().
void QRect::moveRight ( int pos )
Sets the right position of the rectangle to
pos, leaving the size unchanged.
See also right(), setRight(), moveLeft(), moveTop(), and moveBottom().
void QRect::moveTop ( int pos )
Sets the top position of the rectangle to
pos, leaving the size unchanged.
See also top(), setTop(), moveLeft(), moveRight(), and moveBottom().
void QRect::moveTopLeft ( const QPoint & p )
Sets the top-left position of the rectangle to
p, leaving the size unchanged.
See also topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(), and moveBottomLeft().
Examples:
void QRect::moveTopRight ( const QPoint & p )
Sets the top-right position of the rectangle to
p, leaving the size unchanged.
See also topRight(), setTopRight(), moveTopLeft(), moveBottomRight(), and moveBottomLeft().
QRect QRect::normalize () const
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().
Example: scribble/scribble.cpp.
QRect QRect::operator& ( const QRect & r ) const
Returns the intersection of this rectangle and rectangle
r.
Returns an empty rectangle if there is no intersection.
See also operator&=(), operator|(), isEmpty(), intersects(), and contains().
QRect & QRect::operator&= ( const QRect & r )
Intersects this rectangle with rectangle
r.
QRect QRect::operator| ( const QRect & r ) const
Returns the bounding rectangle of this rectangle and rectangle
r.
The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.
See also operator|=(), operator&(), intersects(), and contains().
QRect & QRect::operator|= ( const QRect & r )
Unites this rectangle with rectangle
r.
QCOORD & QRect::rBottom ()
Returns a reference to the bottom coordinate of the rectangle.
See also rLeft(), rTop(), and rRight().
QCOORD & QRect::rLeft ()
Returns a reference to the left coordinate of the rectangle.
See also rTop(), rRight(), and rBottom().
QCOORD & QRect::rRight ()
Returns a reference to the right coordinate of the rectangle.
See also rLeft(), rTop(), and rBottom().
QCOORD & QRect::rTop ()
Returns a reference to the top coordinate of the rectangle.
See also rLeft(), rRight(), and rBottom().
void QRect::rect ( int * x, int * y, int * w, int * h ) const
Extracts the rectangle parameters as the position
*x,
*y and width
*w and height
*h.
See also setRect() and coords().
Examples:
int QRect::right () const
Returns the right coordinate of the rectangle.
See also setRight(), left(), topRight(), and bottomRight().
Examples:
void QRect::setBottom ( int pos )
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().
Example: scribble/scribble.cpp.
void QRect::setBottomLeft ( const QPoint & p )
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().
void QRect::setBottomRight ( const QPoint & p )
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().
void QRect::setCoords ( int xp1, int yp1, int xp2, int yp2 )
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() and setRect().
void QRect::setHeight ( int h )
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().
Example: desktop/desktop.cpp.
void QRect::setLeft ( int pos )
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().
Example: scribble/scribble.cpp.
void QRect::setRect ( int x, int y, int w, int h )
Sets the coordinates of the rectangle's top-left corner to
(x, y), and its size to
(w, h).
See also rect() and setCoords().
Example: themes/wood.cpp.
void QRect::setRight ( int pos )
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().
Example: scribble/scribble.cpp.
void QRect::setSize ( const QSize & s )
Sets the size of the rectangle to
s. The top-left corner is not moved.
See also size(), setWidth(), and setHeight().
Example: xform/xform.cpp.
void QRect::setTop ( int pos )
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().
Example: scribble/scribble.cpp.
void QRect::setTopLeft ( const QPoint & p )
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().
void QRect::setTopRight ( const QPoint & p )
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().
void QRect::setWidth ( int w )
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().
Example: desktop/desktop.cpp.
void QRect::setX ( int x )
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().
See also x() and setY().
void QRect::setY ( int y )
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().
See also y() and setX().
QSize QRect::size () const
Returns the size of the rectangle.
See also width() and height().
Examples:
int QRect::top () const
Returns the top coordinate of the rectangle. Identical to y().
See also setTop(), bottom(), topLeft(), and topRight().
Examples:
QPoint QRect::topLeft () const
Returns the top-left position of the rectangle.
See also setTopLeft(), moveTopLeft(), bottomRight(), left(), and top().
Examples:
QPoint QRect::topRight () const
Returns the top-right position of the rectangle.
See also setTopRight(), moveTopRight(), bottomLeft(), top(), and right().
Example: tictac/tictac.cpp.
QRect QRect::unite ( const QRect & r ) const
Returns the bounding rectangle of this rectangle and rectangle
r. r.unite(s) is equivalent to r|s.
Examples:
int QRect::width () const
Returns the width of the rectangle. The width includes both the left and right edges, i.e. width = right - left + 1.
See also height(), size(), and setHeight().
Examples:
int QRect::x () const
Returns the left coordinate of the rectangle. Identical to left().
See also left(), y(), and setX().
Examples:
int QRect::y () const
Returns the top coordinate of the rectangle. Identical to top().
See also top(), x(), and setY().
Examples:
RELATED FUNCTION DOCUMENTATION
bool operator!= ( const QRect & r1, const QRect & r2 )
Returns TRUE if
r1 and
r2 are different; otherwise returns FALSE.
QDataStream & operator<< ( QDataStream & s, const QRect & r )
Writes the QRect,
r, to the stream
s, and returns a reference to the stream.
See also Format of the QDataStream operators.
bool operator== ( const QRect & r1, const QRect & r2 )
Returns TRUE if
r1 and
r2 are equal; otherwise returns FALSE.
QDataStream & operator>> ( QDataStream & s, QRect & r )
Reads a QRect from the stream
s into rect
r and returns a reference to the stream.
See also Format of the QDataStream operators.
SEE ALSO
http://doc.trolltech.com/qrect.html
http://www.trolltech.com/faq/tech.html
COPYRIGHT
Copyright 1992-2001 Trolltech AS,
http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
AUTHOR
Generated automatically from the source code.
BUGS
If you find a bug in Qt, please report it as described in
http://doc.trolltech.com/bughowto.html.
Good bug reports help us to help you. Thank you.
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
If you find errors in this manual page, please report them to
qt-bugs@trolltech.com.
Please include the name of the manual page (qrect.3qt) and the Qt
version (3.3.3).
Index
- NAME
-
- SYNOPSIS
-
- Public Members
-
- RELATED FUNCTION DOCUMENTATION
-
- DESCRIPTION
-
- MEMBER FUNCTION DOCUMENTATION
-
- QRect::QRect ()
-
- QRect::QRect ( const QPoint & topLeft, const QPoint & bottomRight )
-
- QRect::QRect ( const QPoint & topLeft, const QSize & size )
-
- QRect::QRect ( int left, int top, int width, int height )
-
- void QRect::addCoords ( int xp1, int yp1, int xp2, int yp2 )
-
- int QRect::bottom () const
-
- QPoint QRect::bottomLeft () const
-
- QPoint QRect::bottomRight () const
-
- QPoint QRect::center () const
-
- bool QRect::contains ( const QPoint & p, bool proper = FALSE ) const
-
- bool QRect::contains ( int x, int y ) const
-
- bool QRect::contains ( int x, int y, bool proper ) const
-
- bool QRect::contains ( const QRect & r, bool proper = FALSE ) const
-
- void QRect::coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const
-
- int QRect::height () const
-
- QRect QRect::intersect ( const QRect & r ) const
-
- bool QRect::intersects ( const QRect & r ) const
-
- bool QRect::isEmpty () const
-
- bool QRect::isNull () const
-
- bool QRect::isValid () const
-
- int QRect::left () const
-
- void QRect::moveBottom ( int pos )
-
- void QRect::moveBottomLeft ( const QPoint & p )
-
- void QRect::moveBottomRight ( const QPoint & p )
-
- void QRect::moveBy ( int dx, int dy )
-
- void QRect::moveCenter ( const QPoint & p )
-
- void QRect::moveLeft ( int pos )
-
- void QRect::moveRight ( int pos )
-
- void QRect::moveTop ( int pos )
-
- void QRect::moveTopLeft ( const QPoint & p )
-
- void QRect::moveTopRight ( const QPoint & p )
-
- QRect QRect::normalize () const
-
- QRect QRect::operator& ( const QRect & r ) const
-
- QRect & QRect::operator&= ( const QRect & r )
-
- QRect QRect::operator| ( const QRect & r ) const
-
- QRect & QRect::operator|= ( const QRect & r )
-
- QCOORD & QRect::rBottom ()
-
- QCOORD & QRect::rLeft ()
-
- QCOORD & QRect::rRight ()
-
- QCOORD & QRect::rTop ()
-
- void QRect::rect ( int * x, int * y, int * w, int * h ) const
-
- int QRect::right () const
-
- void QRect::setBottom ( int pos )
-
- void QRect::setBottomLeft ( const QPoint & p )
-
- void QRect::setBottomRight ( const QPoint & p )
-
- void QRect::setCoords ( int xp1, int yp1, int xp2, int yp2 )
-
- void QRect::setHeight ( int h )
-
- void QRect::setLeft ( int pos )
-
- void QRect::setRect ( int x, int y, int w, int h )
-
- void QRect::setRight ( int pos )
-
- void QRect::setSize ( const QSize & s )
-
- void QRect::setTop ( int pos )
-
- void QRect::setTopLeft ( const QPoint & p )
-
- void QRect::setTopRight ( const QPoint & p )
-
- void QRect::setWidth ( int w )
-
- void QRect::setX ( int x )
-
- void QRect::setY ( int y )
-
- QSize QRect::size () const
-
- int QRect::top () const
-
- QPoint QRect::topLeft () const
-
- QPoint QRect::topRight () const
-
- QRect QRect::unite ( const QRect & r ) const
-
- int QRect::width () const
-
- int QRect::x () const
-
- int QRect::y () const
-
- RELATED FUNCTION DOCUMENTATION
-
- bool operator!= ( const QRect & r1, const QRect & r2 )
-
- QDataStream & operator<< ( QDataStream & s, const QRect & r )
-
- bool operator== ( const QRect & r1, const QRect & r2 )
-
- QDataStream & operator>> ( QDataStream & s, QRect & r )
-
- SEE ALSO
-
- COPYRIGHT
-
- AUTHOR
-
- BUGS
-