Take the 2-minute tour ×

Whats is the best way of creating a line (QGraphicsLineItem) which starts at some point on the scene and continues to infinity at some angle.

The way I presently do this is by calculating were the line intersects the view and drawing the line segment.

Is there a better way?

Could I for example set the lines length to some massive number?

share|improve this question
"Could I for example set the lines length to some massive number?" - that's what I would do. Even if the number is very large, Qt should be able to optimize that easily for a single line. –  this.lau_ May 17 '12 at 7:59
Do you want to be the graphics item that large or just draw it infinitely? For the latter one, you could draw it manually. –  leemes May 18 '12 at 0:03
add comment

1 Answer

You could define its paint() and shape() functions so they always use all the space available and needed inside the scene, i.e. inside the visible part of qgraphicsview.


  • Examine mapping functions for qgraphicsview, qgraphicsscene and qgraphicsitem (mapToScene, mapToItem, mapToView or something like that)
  • Define your shape() and paint() functions as if your line is exactly long all over the view (by using the mapping functions above)

So, how ever the user moves his view, repaint will examine the space used by qgraphicsview and draw exactly that long. The illusion is created that the line goes on-and-on.

share|improve this answer
add comment

Your Answer


