|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QGraphicsRectItem Class Reference
[QtGui module]

The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene. More...

    #include <QGraphicsRectItem>

Inherits QAbstractGraphicsShapeItem.

This class was introduced in Qt 4.2.

- List of all members, including inherited members

### Public Functions

- QGraphicsRectItem ( QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- QGraphicsRectItem ( const QRectF & rect, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- QGraphicsRectItem ( qreal x, qreal y, qreal w, qreal h, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- ~QGraphicsRectItem ()
- QRectF rect () const
- void setRect ( const QRectF & rect )
- void setRect ( qreal x, qreal y, qreal w, qreal h )

- 4 public functions inherited from QAbstractGraphicsShapeItem
- 102 public functions inherited from QGraphicsItem

### Additional Inherited Members

- 23 protected functions inherited from QGraphicsItem

## Detailed Description

The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.

To set the item's rectangle, pass a QRectF to QGraphicsRectItem's constructor, or call setRect(). rect() returns the current rectangle.

QGraphicsRectItem uses the rect and the pen width to provide a reasonable implementation of boundingRect(), shape(), and contains(). The paint() function draws the rectangle using the item's associated pen and brush, which you can set by calling setPen() and setBrush().

See also QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, and The Graphics View Framework.

## Member Function Documentation

### QGraphicsRectItem::QGraphicsRectItem ( QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsRectItem. parent and scene are passed to QAbstractGraphicsShapeItem's constructor.

### QGraphicsRectItem::QGraphicsRectItem ( const QRectF & rect, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsRectItem, using rect as the default rectangle. parent and scene are passed to QAbstractGraphicsShapeItem's constructor.

### QGraphicsRectItem::QGraphicsRectItem ( qreal x, qreal y, qreal w, qreal h, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsRectItem with a default rectangle defined by x, y, w and h.

parent is passed to QAbstractGraphicsShapeItem's constructor.

### QGraphicsRectItem::~QGraphicsRectItem ()

Destroys the QGraphicsRectItem.

### QRectF QGraphicsRectItem::rect () const

Returns the item's rectangle.

See also setRect().

### void QGraphicsRectItem::setRect ( const QRectF & rect )

Sets the item's rectangle to rect.

See also rect().

### void QGraphicsRectItem::setRect ( qreal x, qreal y, qreal w, qreal h )

This is an overloaded member function, provided for convenience.

This convenience function is equivalent to calling setRect(QRectF(x, y, w, h));

See also rect().