|  | Home · All Classes · Modules

# QGraphicsPixmapItem Class Reference
[QtGui module]

The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene. More...

Inherits QGraphicsItem.

### Types

- enum ShapeMode { MaskShape, BoundingRectShape, HeuristicMaskShape }

### Methods

- __init__ (self, QGraphicsItem parent = None, QGraphicsScene scene = None)
- __init__ (self, QPixmap pixmap, QGraphicsItem parent = None, QGraphicsScene scene = None)
- QRectF boundingRect (self)
- bool contains (self, QPointF point)
- bool isObscuredBy (self, QGraphicsItem item)
- QPointF offset (self)
- QPainterPath opaqueArea (self)
- paint (self, QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
- QPixmap pixmap (self)
- setOffset (self, QPointF offset)
- setOffset (self, float ax, float ay)
- setPixmap (self, QPixmap pixmap)
- setShapeMode (self, ShapeMode mode)
- setTransformationMode (self, Qt.TransformationMode mode)
- QPainterPath shape (self)
- ShapeMode shapeMode (self)
- Qt.TransformationMode transformationMode (self)
- int type (self)

## Detailed Description

The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.

To set the item's pixmap, pass a QPixmap to QGraphicsPixmapItem's constructor, or call the setPixmap() function. The pixmap() function returns the current pixmap.

QGraphicsPixmapItem uses pixmap's optional alpha mask to provide a reasonable implementation of boundingRect(), shape(), and contains().

The pixmap is drawn at the item's (0, 0) coordinate, as returned by offset(). You can change the drawing offset by calling setOffset().

You can set the pixmap's transformation mode by calling setTransformationMode(). By default, Qt.FastTransformation is used, which provides fast, non-smooth scaling. Qt.SmoothTransformation enables QPainter.SmoothPixmapTransform on the painter, and the quality depends on the platform and viewport. The result is usually not as good as calling QPixmap.scale() directly. Call transformationMode() to get the current transformation mode for the item.

## Type Documentation

### QGraphicsPixmapItem.ShapeMode

This enum describes how QGraphicsPixmapItem calculates its shape and opaque area.

The default value is MaskShape.

Constant | Value | Description
--- | --- | ---
`QGraphicsPixmapItem.MaskShape` | `0` | The shape is determined by calling QPixmap.mask(). This shape includes only the opaque pixels of the pixmap. Because the shape is more complex, however, it can be slower than the other modes, and uses more memory.
`QGraphicsPixmapItem.BoundingRectShape` | `1` | The shape is determined by tracing the outline of the pixmap. This is the fastest shape mode, but it does not take into account any transparent areas on the pixmap.
`QGraphicsPixmapItem.HeuristicMaskShape` | `2` | The shape is determine by calling QPixmap.createHeuristicMask(). The performance and memory consumption is similar to MaskShape.

## Method Documentation

### QGraphicsPixmapItem.__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 QGraphicsPixmapItem. parent is passed to QGraphicsItem's constructor.

See also QGraphicsScene.addItem().

### QGraphicsPixmapItem.__init__ (self, QPixmap pixmap, 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 QGraphicsPixmapItem, using pixmap as the default pixmap. parent is passed to QGraphicsItem's constructor.

See also QGraphicsScene.addItem().

### QRectF QGraphicsPixmapItem.boundingRect (self)

Reimplemented from QGraphicsItem.boundingRect().

### bool QGraphicsPixmapItem.contains (self, QPointF point)

Reimplemented from QGraphicsItem.contains().

### bool QGraphicsPixmapItem.isObscuredBy (self, QGraphicsItem item)

Reimplemented from QGraphicsItem.isObscuredBy().

### QPointF QGraphicsPixmapItem.offset (self)

Returns the pixmap item's offset, which defines the point of the top-left corner of the pixmap, in local coordinates.

See also setOffset().

### QPainterPath QGraphicsPixmapItem.opaqueArea (self)

Reimplemented from QGraphicsItem.opaqueArea().

### QGraphicsPixmapItem.paint (self, QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)

Reimplemented from QGraphicsItem.paint().

### QPixmap QGraphicsPixmapItem.pixmap (self)

Returns the item's pixmap, or an invalid QPixmap if no pixmap has been set.

See also setPixmap().

### QGraphicsPixmapItem.setOffset (self, QPointF offset)

Sets the pixmap item's offset to offset. QGraphicsPixmapItem will draw its pixmap using offset for its top-left corner.

See also offset().

### QGraphicsPixmapItem.setOffset (self, float ax, float ay)

This convenience function is equivalent to calling setOffset(QPointF(x, y)).

This function was introduced in Qt 4.3.

### QGraphicsPixmapItem.setPixmap (self, QPixmap pixmap)

Sets the item's pixmap to pixmap.

See also pixmap().

### QGraphicsPixmapItem.setShapeMode (self, ShapeMode mode)

Sets the item's shape mode to mode. The shape mode describes how QGraphicsPixmapItem calculates its shape. The default mode is MaskShape.

See also shapeMode() and ShapeMode.

### QGraphicsPixmapItem.setTransformationMode (self, Qt.TransformationMode mode)

Sets the pixmap item's transformation mode to mode, and toggles an update of the item. The default mode is Qt.FastTransformation, which provides quick transformation with no smoothing.

Qt.SmoothTransformation enables QPainter.SmoothPixmapTransform on the painter, and the quality depends on the platform and viewport. The result is usually not as good as calling QPixmap.scale() directly.

See also transformationMode().

### QPainterPath QGraphicsPixmapItem.shape (self)

Reimplemented from QGraphicsItem.shape().

### ShapeMode QGraphicsPixmapItem.shapeMode (self)

Returns the item's shape mode. The shape mode describes how QGraphicsPixmapItem calculates its shape. The default mode is MaskShape.

See also setShapeMode() and ShapeMode.

### Qt.TransformationMode QGraphicsPixmapItem.transformationMode (self)

Returns the transformation mode of the pixmap. The default mode is Qt.FastTransformation, which provides quick transformation with no smoothing.

See also setTransformationMode().

### int QGraphicsPixmapItem.type (self)

Reimplemented from QGraphicsItem.type().