本页内容

QGraphicsPolygonItem Class

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

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

公共类型

enum { Type }

公共函数

QGraphicsPolygonItem(QGraphicsItem *parent = nullptr)
QGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = nullptr)
virtual ~QGraphicsPolygonItem()
Qt::FillRule fillRule() const
QPolygonF polygon() const
void setFillRule(Qt::FillRule rule)
void setPolygon(const QPolygonF &polygon)

重新实现的公共函数

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

详细说明

要设置项的多边形,请将QPolygonF 传递给QGraphicsPolygonItem的构造函数,或调用setPolygon()函数。polygon()函数返回当前的多边形。

在原点附近绘制的多边形

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

另请参阅 QGraphicsPathItem 、QGraphicsRectItem 、QGraphicsEllipseItem 、QGraphicsTextItem 、QGraphicsLineItem 、QGraphicsPixmapItem 以及图形视图框架。

成员类型文档

[anonymous] enum

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

常量值描述
QGraphicsPolygonItem::Type5一个图形多边形项

成员函数文档

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

创建一个 QGraphicsPolygonItem。将parent 传递给QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem()。

[explicit] QGraphicsPolygonItem::QGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = nullptr)

创建一个 QGraphicsPolygonItem,并以 `polygon ` 作为默认多边形。`parent ` 将作为参数传递给 `QAbstractGraphicsShapeItem` 的构造函数。

另请参阅 QGraphicsScene::addItem()。

[virtual noexcept] QGraphicsPolygonItem::~QGraphicsPolygonItem()

销毁QGraphicsPolygonItem 。

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

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

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

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

Qt::FillRule QGraphicsPolygonItem::fillRule() const

返回多边形的填充规则。默认填充规则为Qt::OddEvenFill 。

另请参阅 setFillRule()、QPainterPath::fillRule() 和QPainter::drawPolygon()。

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

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

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

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

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

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

QPolygonF QGraphicsPolygonItem::polygon() const

返回该项的多边形;如果未设置多边形,则返回一个空多边形。

另请参阅 setPolygon()。

void QGraphicsPolygonItem::setFillRule(Qt::FillRule rule)

将多边形的填充规则设置为rule 。默认填充规则为Qt::OddEvenFill 。

另请参阅 fillRule()、QPainterPath::fillRule() 和QPainter::drawPolygon()。

void QGraphicsPolygonItem::setPolygon(const QPolygonF &polygon)

将该项的多边形设置为给定的polygon 。

另请参阅 polygon()。

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

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

[override virtual] int QGraphicsPolygonItem::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.