Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QGraphicsItem draw perpendicular line as wide as pen

    General and Desktop
    qt4 qgraphicsitem qline qpen
    1
    1
    937
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 6
      6b656d70 last edited by

      Hi,

      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:

      1. 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
      2. 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.

      Many thanks

      1 Reply Last reply Reply Quote 0
      • First post
        Last post