Point2D direction = (p1 - p0).normalize();Point2D normal(-direction.y, direction.x); Point2D arrow_middle = p1 - direction * arrow_len;Point2D t0 = arrow_middle + normal * arrow_width;Point2D t1 = arrow_middle - normal * arrow_width;FillTriangle(t0, t1, p1);
angle = atan2(p1.y - p0.y, p1.x - p0.x);
QPolygon arrow; arrow << QPoint(0, -arrowWidth/2) << QPoint(arrowHeight, 0) << QPoint(0, arrowWidth/2); QPointF p0(beginPoint); QPointF p1(endPoint); double dx = p1.x() - p0.x(); double dy = p1.y() - p0.y(); double angle = atan2(dy, dx); QPointF p2(p1.x() - arrowHeight * cos(angle), p1.y() - arrowHeight * sin(angle)); double lineLen = sqrt(dx*dx + dy*dy); if(lineLen >= arrowHeight){ painter.drawLine(p0, p2); } painter.save(); painter.translate(p2); painter.rotate(180/3.14159 * angle); painter.drawConvexPolygon(arrow); painter.restore();