Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QRect Class Reference

List of all members.

Detailed Description

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 QPoint and a QSize. The following code creates two identical rectangles.

doc/src/snippets/code/src.corelib.tools.qrect.cpp 0

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 bottom() and right() 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 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 rectange's 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() function 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. The QRect class also provides the intersected() function which returns the intersection rectangle, and the united() function which returns the rectangle that encloses the given rectangle and this:

qrect-intersect.png qrect-unite.png intersected() united()

The isEmpty() function returns true if left() > right() or top() > bottom(). Note that an empty rectangle is not valid: The isValid() function returns true if left() <= right() and top() <= bottom(). A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.

Note that due to the way QRect and QRectF are defined, an empty QRect is defined in essentially the same way as QRectF.

Finally, QRect objects can be streamed as well as compared.

Definition at line 60 of file qrect.h.

Public Member Functions

void adjust (int x1, int y1, int x2, int y2)
QRect adjusted (int x1, int y1, int x2, int y2) const
int bottom () const
QPoint bottomLeft () const
QPoint bottomRight () const
QPoint center () const
bool contains (const QRect &r, bool proper=false) const
bool contains (int x, int y, bool proper) const
bool contains (int x, int y) const
bool contains (const QPoint &p, bool proper=false) const
void getCoords (int *x1, int *y1, int *x2, int *y2) const
void getRect (int *x, int *y, int *w, int *h) const
int height () const
QRect intersect (const QRect &r) const
QRect intersected (const QRect &other) const
bool intersects (const QRect &r) const
bool isEmpty () const
bool isNull () const
bool isValid () const
int left () const
void moveBottom (int pos)
void moveBottomLeft (const QPoint &p)
void moveBottomRight (const QPoint &p)
void moveCenter (const QPoint &p)
void moveLeft (int pos)
void moveRight (int pos)
void moveTo (const QPoint &p)
void moveTo (int x, int t)
void moveTop (int pos)
void moveTopLeft (const QPoint &p)
void moveTopRight (const QPoint &p)
QRect normalized () const
QRect operator & (const QRect &r) const
QRectoperator &= (const QRect &r)
QRect operator| (const QRect &r) const
QRectoperator|= (const QRect &r)
 QRect (int left, int top, int width, int height)
 QRect (const QPoint &topleft, const QSize &size)
 QRect (const QPoint &topleft, const QPoint &bottomright)
 QRect ()
int right () const
void setBottom (int pos)
void setBottomLeft (const QPoint &p)
void setBottomRight (const QPoint &p)
void setCoords (int x1, int y1, int x2, int y2)
void setHeight (int h)
void setLeft (int pos)
void setRect (int x, int y, int w, int h)
void setRight (int pos)
void setSize (const QSize &s)
void setTop (int pos)
void setTopLeft (const QPoint &p)
void setTopRight (const QPoint &p)
void setWidth (int w)
void setX (int x)
void setY (int y)
QSize size () const
int top () const
QPoint topLeft () const
QPoint topRight () const
void translate (const QPoint &p)
void translate (int dx, int dy)
QRect translated (const QPoint &p) const
QRect translated (int dx, int dy) const
QRect unite (const QRect &r) const
QRect united (const QRect &other) const
int width () const
int x () const
int y () const

Private Attributes

int x1
int x2
int y1
int y2


Q_CORE_EXPORT_INLINE bool operator!= (const QRect &, const QRect &)
Q_CORE_EXPORT_INLINE bool operator== (const QRect &, const QRect &)

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QRect &rectangle)
QDataStreamoperator>> (QDataStream &stream, QRect &rectangle)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index