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

QRectF Class Reference

List of all members.


Detailed Description

The QRectF class defines a rectangle in the plane using floating point precision.

A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a QRectF is always equivalent to the mathematical rectangle that forms the basis for its rendering.

A QRectF 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.

        QRectF r1(100, 200, 11, 16);
        QRectF r2(QPoint(100, 200), QSize(11, 16));

There is also a third constructor creating a QRectF from a QRect, and a corresponding toRect() function that returns a QRect object based on the values of this rectangle (note that the coordinates in the returned rectangle are rounded to the nearest integer).

The QRectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. QRectF 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 (otherwise false). The QRectF 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 the rectangle's width or height is less than, or equal to, 0. Note that an empty rectangle is not valid: The isValid() function returns true if both width and height is larger than 0. 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 QRectF is defined in essentially the same way as QRect.

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

Definition at line 510 of file qrect.h.


Public Member Functions

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

Private Attributes

qreal h
qreal w
qreal xp
qreal yp

Friends

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

Related Functions

(Note that these are not member functions.)

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

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

Generated by  Doxygen 1.6.0   Back to index