Reputation: 151
i draw multiple lines with
line = scene->addLine(x1, y1, x2, x2, Pen);
Now i want to add a label at the middle of the line(s) (for example a ellipse or a triangle. Ellipse is maybe the simple solution)
My idea was to calc a new point for Y (newY) and sub a length from x2.
ellipse = scene->addEllipse(x2 - lengthX, newY, w, h, Pen, Brush);
Calc newY:
m = (x2 - x1) / (y2 -y1)
newY = m * x2 - length + x2 -(m * y2)
But he draw the ellipse wrong.
How can i add the label? Am i on the right way?
Upvotes: 0
Views: 931
Reputation: 190
You can use QLineF
class to help you out since it has some nice convenience methods.
First you can easily get the desired point along the line to draw your additional label/shape by using QLineF::pointAt(param)
method.
In addition, if you would like to have your label/shape be oriented along the tangent you can use QLineF::angle()
.
Upvotes: 1