QGraphicsPixmapItem 类
QGraphicsPixmapItem类提供可添加到QGraphicsScene的像素图项目。
Header: | #include < QGraphicsPixmapItem > |
---|---|
qmake: | QT += widgets |
Inherits: | QGraphicsItem |
Inherited By: | |
Since: | Qt 4.2 |
详述
要设置项目的pixmap,可以将QPixmap传递给QGraphicsPixmapItem的构造函数,或者调用setPixmap()函数。函数的作用是:返回当前的像素图。
QGraphicsPixmapItem使用pixmap的可选alpha掩码来提供boundingRect()、shape()和contains()的合理实现。
pixmap是在项目的(0,0)坐标处绘制的,由offset()返回。您可以通过调用setOffset()来更改绘图偏移量。
你可以通过调用setTransformationMode()来设置像素图的转换模式。默认情况下,使用Qt::FastTransformation,它提供了快速、非平滑的缩放。Qt::SmoothTransformation在画家上启用了QPainter::SmoothPixmapTransform,其质量取决于平台和视口。结果通常不如直接调用QPixmap::scale()好。调用transformationMode()获取项目的当前转换模式。
参见QGraphicsPathItem, qgraphicsrectem, QGraphicsEllipseItem, QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsLineItem,和图形视图框架。
公共类型
enum ShapeMode
该枚举描述了QGraphicsPixmapItem如何计算其形状和不透明区域。默认值为MaskShape。
Constant | Value | Description |
---|---|---|
MaskShape | 0 | 形状是通过调用QPixmap::mask()来确定的。此形状仅包含像素图的不透明像素。然而,由于形状更复杂,它可能比其他模式慢,并使用更多的内存。 |
BoundingRectShape | 1 | 形状是通过追踪像素图的轮廓来确定的。这是最快的形状模式,但它不考虑像素图上的任何透明区域。 |
HeuristicMaskShape | 2 | 形状是通过调用QPixmap::createHeuristicMask()确定的。性能和内存消耗与MaskShape相似。 |
enum anonymous
由virtual type()函数返回的值。
Constant | Value | Description |
---|---|---|
Type | 7 | 图形像素图项 |
公共函数
构造析构
- QGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = nullptr)
- QGraphicsPixmapItem(QGraphicsItem *parent = nullptr)
- virtual ~QGraphicsPixmapItem()
偏移
- QPointF offset() const
- void setOffset(const QPointF &offset)
- void setOffset(qreal x, qreal y)
Pixmap
- QPixmap pixmap() const
- void setPixmap(const QPixmap &pixmap)
转换模式
- Qt::TransformationMode transformationMode() const
- void setTransformationMode(Qt::TransformationMode mode)
图形模式
- QGraphicsPixmapItem::ShapeMode shapeMode() const
- void setShapeMode(QGraphicsPixmapItem::ShapeMode mode)
重写的公共函数
- 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 = nullptr) override
- virtual QPainterPath shape() const override
- virtual int type() const override