luckykaa
luckykaa

Reputation: 176

Tracing an outline using Qt Graphics

I'm creating a comic book editor. I want to be able to use some fairly complex customisable shapes for the speech balloons.

I can draw the tail and then draw a balloon but that means I have the outline inside the shape and I want it only around the edge.

I assumed QPainterPath::simplified() would solve the problem but it doesn't seem to do anything.

At the moment my best idea is to draw a shape with a thick outline and then draw it again with no outline but I don't think that will work for "zero width" outlines.

Upvotes: 0

Views: 398

Answers (2)

luckykaa
luckykaa

Reputation: 176

It turns out QPainterPath::simplified() does work. It depends on whether I draw clockwise or anti-clockwise (I believe it works when drawn clockwise), which I presume is down to how Qt's Winding Fill works.

// create a path representing the bubble and its "tail"
QPainterPath tail = tail.shape();
tail.addPath(bubble.shape());
tail.setFillRule(Qt::WindingFill);

painter->drawPath(tail.simplified);

Upvotes: 1

GoBusto
GoBusto

Reputation: 4788

I can think of two possible solutions here:

  • Draw both the "tail" and the main "balloon" as a single shape. In this case, you'd simply draw a single shape with a single outline and a single fill.
  • Draw them separately, but twice. Draw an "expanded" version of the shapes in black first, and then draw the "normal" version of the shapes in white over the top of it. You wouldn't draw any "lines" at all - the "expanded" version of the fill would serve the same purpose.

The first method would allow alternative line styles to be used (dotted or wiggly lines), but the latter would allow the "outline" to be slightly offset, so that it appeared thicker around some edges and thinner around others.

Upvotes: 1

Related Questions