本页内容

QGraphicsPathItem Class

QGraphicsPathItem 类提供了一个路径项,您可以将其添加到QGraphicsScene 中。更多内容...

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

公共类型

enum { Type }

公共函数

QGraphicsPathItem(QGraphicsItem *parent = nullptr)
QGraphicsPathItem(const QPainterPath &path, QGraphicsItem *parent = nullptr)
virtual ~QGraphicsPathItem()
QPainterPath path() const
void setPath(const QPainterPath &path)

重新实现的公共函数

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

详细描述

要设置项的路径,请将QPainterPath 传递给QGraphicsPathItem的构造函数,或调用setPath()函数。path()函数返回当前路径。

在原点附近绘制的路径

QGraphicsPathItem 使用该路径来合理实现boundingRect()、shape() 和contains() 函数。paint() 函数使用与该项关联的笔和画笔绘制路径,您可以通过调用setPen() 和setBrush() 函数来设置这些参数。

另请参阅 QGraphicsRectItem 、QGraphicsEllipseItem 、QGraphicsPolygonItem 、QGraphicsTextItem 、QGraphicsLineItem 、QGraphicsPixmapItem 以及Graphics View Framework。

成员类型文档

[anonymous] enum

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

常量值描述
QGraphicsPathItem::Type2一个图形路径项

成员函数文档

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

构建一个 QGraphicsPath。parent 将作为参数传递给QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem()。

[explicit] QGraphicsPathItem::QGraphicsPathItem(const QPainterPath &path, QGraphicsItem *parent = nullptr)

使用path 作为默认路径,构建一个QGraphicsPath项。parent 将作为参数传递给QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem()。

[virtual noexcept] QGraphicsPathItem::~QGraphicsPathItem()

销毁“QGraphicsPathItem ”。

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

重新实现了:QGraphicsItem::boundingRect() const。

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

重写了:QGraphicsItem::contains(const QPointF &point) const。

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

重写了:QAbstractGraphicsShapeItem::isObscuredBy(const QGraphicsItem *item) const。

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

重新实现了:QAbstractGraphicsShapeItem::opaqueArea() const。

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

重写了:QGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)。

QPainterPath QGraphicsPathItem::path() const

返回该项的路径,格式为QPainterPath 。如果未设置任何项,则返回一个空的QPainterPath 。

另请参阅 setPath()。

void QGraphicsPathItem::setPath(const QPainterPath &path)

将该项目的路径设置为给定的path 。

另请参阅 path()。

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

重新实现了:QGraphicsItem::shape() const。

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

重新实现了:QGraphicsItem::type() const。

© 2026 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.