|  | Home · All Classes · Modules

# QGraphicsRectItem Class Reference
[QtGui module]

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

Inherits QAbstractGraphicsShapeItem.

### Methods

- __init__ (self, QGraphicsItem parent = None, QGraphicsScene scene = None)
- __init__ (self, QRectF, QGraphicsItem parent = None, QGraphicsScene scene = None)
- __init__ (self, float, float, float, float, QGraphicsItem parent = None, QGraphicsScene scene = None)
- QRectF boundingRect (self)
- bool contains (self, QPointF)
- bool isObscuredBy (self, QGraphicsItem)
- QPainterPath opaqueArea (self)
- paint (self, QPainter, QStyleOptionGraphicsItem, QWidget widget = None)
- QRectF rect (self)
- setRect (self, QRectF)
- setRect (self, float, float, float, float)
- QPainterPath shape (self)
- int type (self)

## 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 the setRect() function. The rect() function returns the current rectangle.

QGraphicsRectItem uses the rectangle 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 the setPen() and setBrush() functions.

Note: The rendering of invalid rectangles, such as those with negative widths or heights, is undefined. If you cannot be sure that you are using valid rectangles (for example, if you are creating rectangles using data from an unreliable source) then you should use QRectF.normalized() to create normalized rectangles, and use those instead.

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

## Method Documentation

### QGraphicsRectItem.__init__ (self, QGraphicsItem parent = None, QGraphicsScene scene = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

The scene argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QGraphicsRectItem. parent is passed to QAbstractGraphicsShapeItem's constructor.

See also QGraphicsScene.addItem().

### QGraphicsRectItem.__init__ (self, QRectF, QGraphicsItem parent = None, QGraphicsScene scene = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

The scene argument, if not None, causes self to be owned by Qt instead of PyQt.

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

See also QGraphicsScene.addItem().

### QGraphicsRectItem.__init__ (self, float, float, float, float, QGraphicsItem parent = None, QGraphicsScene scene = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

The scene argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QGraphicsRectItem with a default rectangle defined by (x, y) and the given width and height.

parent is passed to QAbstractGraphicsShapeItem's constructor.

See also QGraphicsScene.addItem().

### QRectF QGraphicsRectItem.boundingRect (self)

Reimplemented from QGraphicsItem.boundingRect().

### bool QGraphicsRectItem.contains (self, QPointF)

Reimplemented from QGraphicsItem.contains().

### bool QGraphicsRectItem.isObscuredBy (self, QGraphicsItem)

Reimplemented from QGraphicsItem.isObscuredBy().

### QPainterPath QGraphicsRectItem.opaqueArea (self)

Reimplemented from QGraphicsItem.opaqueArea().

### QGraphicsRectItem.paint (self, QPainter, QStyleOptionGraphicsItem, QWidget widget = None)

Reimplemented from QGraphicsItem.paint().

### QRectF QGraphicsRectItem.rect (self)

Returns the item's rectangle.

See also setRect().

### QGraphicsRectItem.setRect (self, QRectF)

Sets the item's rectangle to be the given rectangle.

See also rect().

### QGraphicsRectItem.setRect (self, float, float, float, float)

Sets the item's rectangle to the rectangle defined by (x, y) and the given width and height.

This convenience function is equivalent to calling `setRect(QRectF(x, y, width, height))`

See also rect().

### QPainterPath QGraphicsRectItem.shape (self)

Reimplemented from QGraphicsItem.shape().

### int QGraphicsRectItem.type (self)

Reimplemented from QGraphicsItem.type().