Usage of QPen which is cosmetic but not width zero

484 views Asked by At

I have recently migrated an application from Qt 4 to Qt 5. I used to use a default QPen() with width zero which was therefore cosmetic. After migration I couldn't leave it as default (the default pen has changed to be of width 1 and therefore not cosmetic). So I simply added a call to setCosmetic(True) so my pens were cosmetic but width 1.

However, this led to some unexpected (to me) behaviour. In particular I had some QGraphicsEllipseItem objects which were giving incorrect selection behaviour: specifically, a very small ellipse, scaled up to a large size, would have a much larger shape() than it was being drawn. It was being drawn with a cosmetic (1 pixel) pen but the shape was calculated as if the pen was of size 1 scaled up.

This is easily fixed: I simply set the QPen width to 0. But it raised a question in my mind.

What is the intended semantics of a cosmetic pen with non-zero width? Is this behaviour of the QGraphicsEllipseItem intended, and with useful application, or is it unexpected?

1

There are 1 answers

1
Martin Hennings On BEST ANSWER

See the documentation for QGraphicsItem::paint():

QGraphicsItem does not support use of cosmetic pens with a non-zero width.