PDA

View Full Version : Scaling of pen width in QGraphicsView



spuds
29th May 2008, 04:01
I am following the examples in Chapter 7 of Johan Thelin's book "Foundations of Qt Development". Simply put, I am creating a QQraphicsRectItem that is added to a QGraphicsScene as part of a QGraphicsView. I can then interact with the RectItem through handles that are also detailed in Chapter 7 of that book. All works fine, except large scaling. The rectangle expands and contracts appropriately but so does the line width of the border of the rectangle and any fill pattern is also scaled. With a pen width set to 1, a large horizontal drag expanding the width of the rectangle also results in the two side borders getting expanded to an apparent pen width of like 3 to 4. My question is whether I can change the size of the rectangle while keeping the pen width at 1 or whatever size I choose?

wysota
29th May 2008, 08:01
Yes. Set the pen as "cosmetic" and it will remain one pixel wide regardless of the transformation.

Brandybuck
29th May 2008, 18:20
A pen width of 0 is "cosmetic", and will always be one pixel/dot wide.

spuds
30th May 2008, 02:47
wysota and BrandyBuck,

Thanks for the reply. The 0 width cosmetic pen works as you said and is independent of any painter transformations. I had seen the o widthe pen in the documentation a month ago or so and wondered why anyone would ever use a 0 width pen. I didn't read close enough. Again thanks.