Unsolved QGraphicsItem draw perpendicular line as wide as pen
I am working in PyQt but am comfortable with any help written in C++.
I have an application that contains a number of custom QGraphicsItems that are essentially a series of straight lines rendered as a painter path. The lines are all drawn with cosmetic pens of various thicknesses > 1.
What I am trying to do is draw a line of a given thickness that has a single pixel 'end cap' in a different color, for example:
Where | is an end cap and = represents the main line.
This should allow me to draw two lines of the same color and have a single pixel demarcation between them (it may have two pixels in the middle, but that is fine too):
I can think of two ways to attack this:
- Draw the line in the 'end cap' color and then draw a second line shorter by two pixels (one at either end) over the top
- Draw the line and then draw another perpendicular line at each end, this line would use a cosmetic pen of width 1.
The issue with 1 is that I am not sure how to make the line shorter by the equivalent of 2x the end cap width.
The issue with 2 is that i do not know how to draw a line as long as the pen is wide.
I suspect the answer lies in using some of the translations between coordinate systems, but I cannot work out where to start.