QGraphicsPixmapItem Class

QGraphicsPixmapItem 类提供了一个像素图项,您可以将其添加到QGraphicsScene... 更多...

头文件: #include <QGraphicsPixmapItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QGraphicsItem

公共类型

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

公共函数

QGraphicsPixmapItem(QGraphicsItem *parent = nullptr)
QGraphicsPixmapItem(const QPixmap &pixmap, 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 使用 pixmap 的可选 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::MaskShape0形状通过调用QPixmap::mask() 确定。该形状只包括像素图中不透明的像素。不过,由于形状更为复杂,它可能比其他模式更慢,而且会占用更多内存。
QGraphicsPixmapItem::BoundingRectShape1形状是通过追踪像素图的轮廓确定的。这是最快的形状模式,但它不考虑像素图上的任何透明区域。
QGraphicsPixmapItem::HeuristicMaskShape2形状是通过调用QPixmap::createHeuristicMask() 确定的。其性能和内存消耗与 MaskShape 相似。

enum QGraphicsPixmapItem::anonymous

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

常量说明
QGraphicsPixmapItem::Type7图形像素图项

成员函数文档

[explicit] QGraphicsPixmapItem::QGraphicsPixmapItem(QGraphicsItem *parent = nullptr)

构造一个 QGraphicsPixmapItem。parent 传递给QGraphicsItem 的构造函数。

另请参阅 QGraphicsScene::addItem().

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

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

另请参阅 QGraphicsScene::addItem().

[virtual noexcept] 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

以本地坐标返回像素图项的偏移量,该偏移量定义了像素图左上角的位置。

另请参阅 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)

将像素图项的偏移量设置为offsetQGraphicsPixmapItem 将使用offset 作为左上角绘制像素图。

另请参阅 offset() 。

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

该方便函数等同于调用 setOffset(QPointF(x,y)) 。

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 在绘制器上启用 ,质量取决于平台和视口。效果通常不如直接调用 QPixmap::scale() 好。QPainter::SmoothPixmapTransform

另请参阅 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.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.