QRect Class Reference


The QRect class defined a rectangle in the plane. (details) (complete member list)

#include <qrect.h>

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

The QRect class defined 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 as short). The minimum value of QCOORD is -32768 and the maximum value is 32767.

Notice that the size (width and height) of a rectange might be different from what you are used to. If the top left corner and the bottom right corner are the same, then the height and the width of the rectange will both be one.

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, where 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 is assumed to have its origo (0,0) in the top left corner, the positive direction of the y axis is downwards and the positive x axis is from the left to the right.

See also: QPoint and QSize.


Member Function Documentation

QRect::QRect ()

Constructs a rectangle with undefined position and size.

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 (QCOORD left, QCOORD top, QCOORD width, QCOORD height)

Constructs a rectangle with the a top left corner and a width and a height.

QCOORD QRect::bottom () const

Returns the bottom coordinate of the rectangle.

QPoint QRect::bottomLeft () const

Returns the bottom left position of the rectangle.

QPoint QRect::bottomRight () const

Returns the bottom right position of the rectangle.

QPoint QRect::center () const

Returns the center point of the rectangle.

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.

If proper is TRUE, this function returns TRUE only if p is inside (not on the edge).

bool QRect::contains (const QRect &r, bool proper=FALSE) const

Returns TRUE if the rectangle r is inside or if it touches an edge of this rectangle.

If proper is TRUE, this function returns TRUE only if r is inside (not on the edge).

void QRect::coords (int *xp1, int *yp1, int *xp2, int *yp2) const

Extracts the rectangle parameters as the top left point and the bottom right point.

void QRect::fixup ()

Repairs an invalid rectangle.

It swaps left and right if left() > right(), and swaps top and bottom if top() > bottom().

See also: isValid().

QCOORD QRect::height () const

Returns the height of the rectangle.

height = bottom - top + 1.

QRect QRect::intersect (const QRect &r) const

Returns the intersection rectangle of this rectangle and r.

The returned rectangle will be empty if there is no intersection.

See also: isEmpty().

bool QRect::intersects (const QRect &r) const

Returns TRUE if this rectangle intersects with r.

bool QRect::isEmpty () const

Returns TRUE if the rectangle is empty, or FALSE if it is not empty.

An empty rectangle has a left() > right() or top() > bottom().

An empty rectangle is not valid.

See also: isValid().

bool QRect::isNull () const

Returns TRUE if the rectangle is a null rectangle.

A null rectangle has both the width and the height set to 0, that is right() == left() - 1 and bottom() == top() - 1.

Remember that if right() == left() and bottom() == top(), then we have a rectangle with 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 if the rectangle is valid, or FALSE if it is invalid.

A valid rectangle has a left() <= right() and top() <= bottom().

QCOORD QRect::left () const

Returns the left coordinate of the rectangle.

void QRect::move (int dx, int dy)

Moves the rectangle dx along the X axis and dy along the Y axis.

void QRect::rect (int *x, int *y, int *w, int *h) const

Extracts the rectangle parameters as the position and the size.

QCOORD QRect::right () const

Returns the right coordinate of the rectangle.

void QRect::setBottom (QCOORD pos)

Sets the bottom position of the rectangle, possibly changing the height.

See also: bottom().

void QRect::setBottomLeft (const QPoint &p)

Sets the bottom left position of the rectangle to p, leaving the size unchanged.

void QRect::setBottomRight (const QPoint &p)

Sets the bottom right position of the rectangle to p, leaving the size unchanged.

void QRect::setCenter (const QPoint &p)

Sets the center point of the rectangle to p, leaving the size unchanged.

void QRect::setCoords (int xp1, int yp1, int xp2, int yp2)

Sets the rectangle to a top left position and bottom right position.

void QRect::setLeft (QCOORD pos)

Sets the left position of the rectangle, possibly changing the width.

void QRect::setRect (int x, int y, int w, int h)

Sets the rectangle to a top left position and a size.

void QRect::setRight (QCOORD pos)

Sets the right position of the rectangle, possibly changing the width.

See also: right().

void QRect::setSize (const QSize &s)

Sets the size of the rectangle to s.

void QRect::setTop (QCOORD pos)

Sets the top position of the rectangle, possibly changing the height.

void QRect::setTopLeft (const QPoint &p)

Sets the top left position of the rectangle to p, leaving the size unchanged.

void QRect::setTopRight (const QPoint &p)

Sets the top right position of the rectangle to p, leaving the size unchanged.

void QRect::setX (QCOORD x)

Sets the x (left) position of the rectangle, possibly changing the width.

Synonymous to setLeft().

void QRect::setY (QCOORD y)

Sets the y (top) position of the rectangle, possibly changing the height.

Synonymous to setTop().

QSize QRect::size () const

Returns the size of the rectangle.

QCOORD QRect::top () const

Returns the top coordinate of the rectangle.

QPoint QRect::topLeft () const

Returns the top left position of the rectangle.

QPoint QRect::topRight () const

Returns the top right position of the rectangle.

QRect QRect::unite (const QRect &r) const

Returns the union rectangle of this rectangle and r.

QCOORD QRect::width () const

Returns the width of the rectangle.

width = right - left + 1.

QCOORD QRect::x () const

Returns the left coordinate of the rectangle.

Synonymous to left().

QCOORD QRect::y () const

Returns the top coordinate of the rectangle.

Synonymous to top().


Related Functions

bool operator== (const QRect &r1, const QRect &r2)

Returns TRUE if r1 and r2 are equal, or FALSE if they are different.

bool operator!= (const QRect &r1, const QRect &r2)

Returns TRUE if r1 and r2 are different, or FALSE if they are equal.

QDataStream & operator<< (QDataStream &s, const QRect &r)

Writes a QRect to the stream.

The output format is four INT16 (order: left, top, right, bottom).

QDataStream & operator>> (QDataStream &s, QRect &r)

Reads a QRect from the stream.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech