QGraphicsPixmapItem 类

QGraphicsPixmapItem 类提供的像素图项可以被添加到 QGraphicsScene . 更多...

头: #include <QGraphicsPixmapItem>
qmake: QT += widgets
Since: Qt 4.2
继承: QGraphicsItem

该类在 Qt 4.2 引入。

公共类型

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

公共函数

QGraphicsPixmapItem (const QPixmap & pixmap , QGraphicsItem * parent = nullptr)
QGraphicsPixmapItem (QGraphicsItem * parent = nullptr)
virtual ~QGraphicsPixmapItem ()
QPointF offset () const
QPixmap pixmap () const
void setOffset (const QPointF & offset )
void setOffset (qreal x , qreal y )
void setPixmap (const QPixmap & pixmap )
void setShapeMode (QGraphicsPixmapItem::ShapeMode mode )
void setTransformationMode (Qt::TransformationMode mode )
QGraphicsPixmapItem::ShapeMode shapeMode () const
Qt::TransformationMode transformationMode () const

重实现公共函数

virtual QRectF boundingRect () const override
virtual bool contains (const QPointF & point ) const override
virtual bool isObscuredBy (const QGraphicsItem * item ) const override
virtual QPainterPath opaqueArea () const override
virtual void paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget ) override
virtual QPainterPath shape () const override
virtual int type () const override

详细描述

要设置项的像素图,传递 QPixmap 到 QGraphicsPixmapItem 的构造函数,或调用 setPixmap () 函数。 pixmap () 函数返回当前像素图。

QGraphicsPixmapItem 使用像素图的可选 Alpha 遮罩来提供合理实现的 boundingRect (), shape (),和 contains ().

像素图的绘制在项的 (0, 0) 坐标处,作为返回通过 offset ()。可以改变绘制偏移通过调用 setOffset ().

可以设置像素图的变换模式通过调用 setTransformationMode ()。默认情况下, Qt::FastTransformation 的使用,提供快速、非平滑的比例缩放。 Qt::SmoothTransformation 启用 QPainter::SmoothPixmapTransform 在描绘器,且品质从属平台和视口。结果通常不如直接调用 QPixmap::scale() 好。调用 transformationMode () 以获取项的当前变换模式。

另请参阅 QGraphicsPathItem , QGraphicsRectItem , QGraphicsEllipseItem , QGraphicsTextItem , QGraphicsPolygonItem , QGraphicsLineItem ,和 图形视图框架 .

成员类型文档编制

enum QGraphicsPixmapItem:: ShapeMode

此枚举描述如何 QGraphicsPixmapItem 计算其形状和不透明区域。

默认值为 MaskShape。

常量 描述
QGraphicsPixmapItem::MaskShape 0 形状的确定是通过调用 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.

enum QGraphicsPixmapItem:: anonymous

值的返回通过虚拟 type () 函数。

常量 描述
QGraphicsPixmapItem::Type 7 图形像素图项

成员函数文档编制

QGraphicsPixmapItem:: QGraphicsPixmapItem (const QPixmap & pixmap , QGraphicsItem * parent = nullptr)

构造 QGraphicsPixmapItem,使用 pixmap 作为默认像素图。 parent 会被传递给 QGraphicsItem 的构造函数。

另请参阅 QGraphicsScene::addItem ().

QGraphicsPixmapItem:: QGraphicsPixmapItem ( QGraphicsItem * parent = nullptr)

构造 QGraphicsPixmapItem。 parent 会被传递给 QGraphicsItem 的构造函数。

另请参阅 QGraphicsScene::addItem ().

[virtual] QGraphicsPixmapItem:: ~QGraphicsPixmapItem ()

销毁 QGraphicsPixmapItem .

[override virtual] QRectF QGraphicsPixmapItem:: boundingRect () const

重实现: QGraphicsItem::boundingRect () const.

[override virtual] bool QGraphicsPixmapItem:: contains (const QPointF & point ) const

重实现: QGraphicsItem::contains (const QPointF &point) const.

[override virtual] bool QGraphicsPixmapItem:: isObscuredBy (const QGraphicsItem * item ) const

重实现: QGraphicsItem::isObscuredBy (const QGraphicsItem *item) const.

QPointF QGraphicsPixmapItem:: offset () const

返回像素图项的 offset ,以本地坐标定义像素图的左上角点。

另请参阅 setOffset ().

[override virtual] QPainterPath QGraphicsPixmapItem:: opaqueArea () const

重实现: QGraphicsItem::opaqueArea () const.

[override virtual] void QGraphicsPixmapItem:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget )

重实现: QGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).

QPixmap QGraphicsPixmapItem:: pixmap () const

返回项的像素图,或无效 QPixmap 若没有设置像素图。

另请参阅 setPixmap ().

void QGraphicsPixmapItem:: setOffset (const QPointF & offset )

将像素图项的偏移设为 offset . QGraphicsPixmapItem will draw its pixmap using offset for its top-left corner.

另请参阅 offset ().

void QGraphicsPixmapItem:: setOffset ( qreal x , qreal y )

此方便函数相当于调用 setOffset( QPointF ( x , y )).

该函数在 Qt 4.3 引入。

void QGraphicsPixmapItem:: setPixmap (const QPixmap & pixmap )

将项的像素图设为 pixmap .

另请参阅 pixmap ().

void QGraphicsPixmapItem:: setShapeMode ( QGraphicsPixmapItem::ShapeMode mode )

将项的形状模式设为 mode 。形状模式描述如何 QGraphicsPixmapItem 计算其形状。默认模式为 MaskShape .

另请参阅 shapeMode () 和 ShapeMode .

void QGraphicsPixmapItem:: setTransformationMode ( Qt::TransformationMode mode )

将像素图项的变换模式设为 mode ,并触发项的更新。默认模式为 Qt::FastTransformation ,提供没有平滑的快速变换。

Qt::SmoothTransformation 启用 QPainter::SmoothPixmapTransform 在描绘器,且品质从属平台和视口。结果通常不如直接调用 QPixmap::scale() 好。

另请参阅 transformationMode ().

[override virtual] QPainterPath QGraphicsPixmapItem:: shape () const

重实现: QGraphicsItem::shape () const.

QGraphicsPixmapItem::ShapeMode QGraphicsPixmapItem:: shapeMode () const

返回项的形状模式。形状模式描述如何 QGraphicsPixmapItem 计算其形状。默认模式为 MaskShape .

另请参阅 setShapeMode () 和 ShapeMode .

Qt::TransformationMode QGraphicsPixmapItem:: transformationMode () const

返回像素图的变换模式。默认模式为 Qt::FastTransformation ,提供没有平滑的快速变换。

另请参阅 setTransformationMode ().

[override virtual] int QGraphicsPixmapItem:: type () const

重实现: QGraphicsItem::type () const.