我正在尝试绘制箭头,所以我只是参考了可以绘制箭头的示例代码:
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)
和线从同一点开始?我需要在绘制箭头后开始这条线。原因有时是如果笔宽增加箭头看起来比线小。