[Development] Proposal: Make QPen non-cosmetic by default

Bache-Wiig Jens Jens.Bache-Wiig at digia.com
Thu Oct 11 10:58:13 CEST 2012


This issue came up while preparing some code to be High-dpi aware but it is really a completely separate issue.
While I previously supported the idea that cosmetic pens should be two pixels wide by default on HDPI screens, I think we should take it one step further as the real issue is caused by the default values of QPen.

QPen defaults to a pen width of 0, which might or might not be an intentional behaviour.  This is interpreted as a Cosmetic pen which will have 1 pixel thickness regardless of the scale on the scene. Any code that simply does painter->setPen(someColor) will have this behaviour. 

The only way to avoid it is to explicitly create a QPen(Qt::Black, 1.0). Since normally there would be no difference between these behaviours, I assume that the majority of code will simply ignore the pen with altogether. Most existing styles certainly does this and mostly break with HDPI set unless every pen is explicitly set to 1.0.

I have personally never seen an actual use case where a cosmetic pen makes sense, but  I assume there are reasons for having i so anyone creating an explicit QPen(Qt::black, 0.0) should get a 1.0 pixel thick line regardless of scaling.

With this in mind, I would propose that we change the initialisation value of QPen to be 1.0 for pen width by default in Qt5, and invert the name and behaviour of the QPainter::NonCosmeticDefaultPen render hint. Most code should not be affected by it and code that depends on this really needs cosmetic pen should already be initialising their QPen explicitly.

Regards,
Jens





More information about the Development mailing list