矢印を描画しようとしているので、矢印を描画できるサンプル コードを参照しました。
http://doc.qt.io/qt-5/qtwidgets-graphicsview-elasticnodes-edge-cpp.html
同じ式を使用して描画することにし、次のように試しました。
theCurrentLine->setP1(QPointF(0, 0) );
theCurrentLine->setP2((theLineVector));
p->drawLine(*theCurrentLine);
double angle = ::acos(theCurrentLine->dx() / theCurrentLine->length());
if (theCurrentLine->dy() >= 0)
angle = TwoPi - angle;
QPointF sourcePoint = QPointF(0,0);
QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * theArrowSize,
cos(angle + Pi / 3) * theArrowSize);
QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * theArrowSize,
cos(angle + Pi - Pi / 3) * theArrowSize);
p->drawPolygon(QPolygonF() << theCurrentLine->p1() << sourceArrowP1 << sourceArrowP2);
しかし、矢印の頭のポリゴンが描画された後に線を描画したいと思います。
ポリゴンの後に開始できるのP1()
値を変更するにはどうすればよいですか? 矢印の頭が描かれた後に線を開始する必要があります。その理由は、ペンの幅が大きくなると、矢印の頭が線よりも小さく見えることがあります。theCurrentLine
polygon(arrowHead)