[Development] New high-dpi QPen proposal (Was Re: Proposal: Make QPen non-cosmetic by default)

Samuel Rødal samuel.rodal at digia.com
Thu Oct 18 12:05:45 CEST 2012

On 10/18/2012 11:08 AM, Bache-Wiig Jens wrote:
>> Maybe as a best effort we could introduce a different render hint,
>> asking QPainter to treat cosmetic pens as geometric, would be a better
>> solution for Morten's high-dpi use case. Then it would be opt-in instead
>> of opt-out, and no existing applications would be affected. Turning on
>> high-dpi mode could be documented to also set the render hint.
> ...
>> In summary (or TL;DR), my new proposal would be to just make
>> QPainter::NonCosmeticDefaultPen work as advertised, and have it be set
>> by default when high-dpi mode is enabled. This way there would be
>> minimal breakage of existing code. Thoughts?
> No I don't think this would work. That way we will get the obscure scalability issues that Uwe mentioned but it would only happen on retina capable computers so it can become even harder to discover.

True, the fact that applications that are tested and working on 
non-retina suddenly break on retina will cause confusing behavior even 
for applications written from scratch with Qt 5. Assuming we have as a 
goal that applications should work in high-dpi mode without any testing 
or modifications being needed. Morten, is that the case?

> The original proposal doesn't really have these problems though. We already set the render hint NonCosmeticPenByDefault on GraphicsView to avoid inconsistent scalability issues there and keep style code working when being scaled.

That's why I figured that setting it for high-dpi would make sense as 
well, but at least in the QGraphicsView case you wouldn't get any 
surprises since it's always set. Having a potentially breaking behavior 
depend on whether high-dpi is enabled or not might not be a good idea 
after all...

> I think we should extend this behavior to QPainter in general by only initialising QPen to 1 instead of 0. We keeping the explicit 0-pen working as before. In addition, we introduce a CosmeticPenByDefault render hint  that Qwt can set on its painter to make all pens cosmetic by default. (not just 0-pen) Though the Qt4PainterRenderHint could still explicitly give only 0 pen cosmetic properties.

I'm not sure Qwt actually _wants_ all pens to be cosmetic by default. 
For > 0 width pens it must already have had explicit calls to 
setCosmetic(true), so it's really only the default-constructed QPens 
that would be an issue. So I don't see how CosmeticPenByDefault would be 
needed in addition to Qt4CompatiblePainting.


More information about the Development mailing list