Qt drawing lines
-
We are building a tool using QT for some of our research. The input for our tool is a data flow model where we specify the flow of data from one actor to another. In simple words, we have different actors connected each other by lines.
We are specifying the lines currently as a line segment, (x_start, y_start) to (x_end, y_end). So when QT draws it, it draws a line as shown in Figure 1.
http://imageshack.us/photo/my-images/407/32971773.png/
What we want: When we specify end points of line (x_start, y_start) to (x_end, y_end), it should draw a line as shown in Figure 2.
http://imageshack.us/photo/my-images/402/84772692.png/
Is there any easy way to achieve this?
Thanks in advance.
-
Not all that difficult, but there is no automated way to do it. However, it would just be a few lines of code...
-
Thanks Andre for responding. Could you describe the idea that you have in mind? I also want the lines not to run over some existing actor. Currently it is drawing on top of another actor.
-
You should give a try to some thinking, it's not difficult but time-taking.
Simple polyline connection can be done like this:
@
QPoint points[4]={
QPoint(x_start,y_start),
QPoint((x_start+x_end)/2,y_start),
QPoint((x_start+x_end)/2,y_end),
QPoint(x_end,y_end)
};painter.drawPolyline(points,4);
@
-
[quote author="knmaheshy2k" date="1319840368"]Thanks Andre for responding. Could you describe the idea that you have in mind? I also want the lines not to run over some existing actor. Currently it is drawing on top of another actor.
[/quote]
Hmmm... That is a complication that you did not mention before. You will have to come up with finding a suitable path yourself then. That is something Qt can not help you with.
-
I would start to google for some autorouting autolayouting code for that.
Qt does not have that build in.