1

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
4

1 に答える 1

0

path() は QPainterPath を返すため、パスを次のように変更する必要があります。

void QPainterPath::setElementPositionAt(int index, qreal x, qreal y)

次に、QGraphicsPathItem へのパスを再設定します。

以下にサンプルを示します。

QPainterPath p = item->path();
p.setElementPositionAt(0, 0, -5);
item->setPath(p);

以下も使用することをお勧めします。

パス->要素カウント()

変更するインデックスが範囲内にあることを確認します。

于 2013-09-17T06:38:43.350 に答える