有没有办法在Qt中修改QGraphicsPathItem的路径?
我是这样创建项目的:
QGraphicsPathItem* item = new QGraphicsPathItem();
QPainterPath* path = new QPainterPath();
path->cubicTo(3,5, 3,10, 0,15);
item->setPath(*path);
item->moveBy(-20,-20);
scene->addItem(item);现在我想修改路径的元素:
item->path().elementAt(0).y = -5;
item->path().elementAt(0).x = 0;但我得到以下错误:
assignment of member 'QPainterPath::Element::y' in read-only object发布于 2013-09-17 14:38:43
由于QPainterPath ()返回一个路径,因此您需要使用以下命令修改路径:
void QPainterPath::setElementPositionAt(int index, qreal x, qreal y)然后重新设置QGraphicsPathItem的路径。
下面是一个示例:
QPainterPath p = item->path();
p.setElementPositionAt(0, 0, -5);
item->setPath(p);明智的做法是同时使用:
path->elementCount()
以确保您要修改的索引在范围内。
https://stackoverflow.com/questions/16877667
复制相似问题