QGraphicsPixmapItem Class

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

Header: #include <QGraphicsPixmapItem>
qmake: QT += widgets
Since: Qt 4.2
Inherits: QGraphicsItem

This class was introduced in Qt 4.2.

Public Types

enum ShapeMode { MaskShape, BoundingRectShape, HeuristicMaskShape }
enum anonymous { Type }

Detailed Description

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.

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

Member Type Documentation

enum QGraphicsPixmapItem::ShapeMode

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

The default value is MaskShape.

ConstantValueDescription
QGraphicsPixmapItem::MaskShape0The 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::BoundingRectShape1The 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::HeuristicMaskShape2The shape is determine by calling QPixmap::createHeuristicMask(). The performance and memory consumption is similar to MaskShape.

enum QGraphicsPixmapItem::anonymous

The value returned by the virtual type() function.

ConstantValueDescription
QGraphicsPixmapItem::Type7A graphics pixmap item