如何给qgraphicsrectitem 的边框添加箭头
时间: 2023-03-27 11:01:23 浏览: 288
您可以使用QPainterPath类来创建一个带有箭头的路径,然后使用QGraphicsPathItem类将其添加到QGraphicsScene中。具体实现可以参考以下代码:
QGraphicsRectItem *rectItem = new QGraphicsRectItem(, , 100, 100);
QPainterPath path;
path.addRect(rectItem->rect());
path.moveTo(rectItem->rect().topRight());
path.lineTo(rectItem->rect().bottomRight());
path.addPolygon(QPolygonF() << QPointF(rectItem->rect().right(), rectItem->rect().center().y())
<< QPointF(rectItem->rect().right() + 10, rectItem->rect().center().y() - 10)
<< QPointF(rectItem->rect().right() + 10, rectItem->rect().center().y() + 10));
QGraphicsPathItem *pathItem = new QGraphicsPathItem(path);
pathItem->setPen(QPen(Qt::black));
scene->addItem(pathItem);
这样就可以在QGraphicsRectItem的右侧添加一个带有箭头的边框了。
阅读全文