Qt-interest Archive, April 2008
QGraphics Pen width ignoring transformation
Message 1 in thread
I would like to draw some items on a QGraphicsScene with a constant pen width
of say 2 pixels despite the scaling. Is this possible.
Take for example that i am drawing the border of a custom item with
pen.setWidth(2). i want the size to scale with the item but i want the line
to remain 2 pixels. This is the effect i get with pen width 0 but that's too
thin.
Is this possible?
--
[ signature omitted ]
Message 2 in thread
On Wed, 09 Apr 2008 11:47:47 +0200, kitts <kitts.mailinglists@xxxxxxxxx>
wrote:
> I would like to draw some items on a QGraphicsScene with a constant pen
> width
> of say 2 pixels despite the scaling. Is this possible.
>
> Take for example that i am drawing the border of a custom item with
> pen.setWidth(2). i want the size to scale with the item but i want the
> line
> to remain 2 pixels. This is the effect i get with pen width 0 but that's
> too
> thin.
>
> Is this possible?
Yep, use pen.setCosmetic(true).
--
[ signature omitted ]
Message 3 in thread
On Wednesday 09 April 2008 15:32:18 Samuel RÃdal wrote:
> On Wed, 09 Apr 2008 11:47:47 +0200, kitts <kitts.mailinglists@xxxxxxxxx>
>
> wrote:
> > I would like to draw some items on a QGraphicsScene with a constant pen
> > width
> > of say 2 pixels despite the scaling. Is this possible.
> >
> > Take for example that i am drawing the border of a custom item with
> > pen.setWidth(2). i want the size to scale with the item but i want the
> > line
> > to remain 2 pixels. This is the effect i get with pen width 0 but that's
> > too
> > thin.
> >
> > Is this possible?
>
> Yep, use pen.setCosmetic(true).
That's just what i was looking for! Qt just never fails to amaze me! :-)
--
[ signature omitted ]
Message 4 in thread
>>
>> Yep, use pen.setCosmetic(true).
>
> That's just what i was looking for! Qt just never fails to amaze me! :-)
> --
But it is not working if you set a Style to the pen, only for a solid line.
This was then considered as a bug in the documentation by Trolltech and I
was told following change for Qt 4.4:
"Make sure to constrain all painting inside the boundaries of
boundingRect() to avoid rendering artifacts (as QGraphicsView does not
clip the painter for you). In particular, when QPainter renders the
outline of a shape using an assigned QPen, half of the outline will be
drawn outside, and half inside, the shape you're rendering (e.g., with
a pen width of 2 units, you must draw outlines 1 unit inside
boundingRect()). QGraphicsItem does not support use of cosmetic pens
with a non-zero width."
So a cosmetic pen with width > 0 is not supported any more.
Markus
--
[ signature omitted ]