[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 09:59:45 CEST 2012


On 10/18/2012 07:53 AM, Uwe Rathmann wrote:
> On Wed, 17 Oct 2012 16:47:00 +0200, Samuel Rødal wrote:
>
>> Seems to me to be the best compromise to avoid completely breaking too
>> much existing code.
>
> I don't agree - it is going to break many applications doing graphics and
> PDF export for a micro modification that isn't much better than the
> existing API. Is this really worth the incompatibility ?
>
> Please have in mind that for Qwt I will have the problem that all pens
> are created in application code, while the painter ( and its render hints
> ) is usually created inside of the Qwt library. An exception are f.e.
> report generators: here the exported plot is part of a document and the
> application creates the painter passing it together with a target
> rectangle to Qwt.
>
> I have no idea how to hide the incompatibility inside of the Qwt library.
> I'm afraid in the end it will be something every Qwt application has to
> handle manually.

You _could_ set the QPainter:Qt4CompatiblePainting on the painter, and 
users of your library could unset it once they made sure their QPen code 
didn't break by doing so.

Although, I'm starting to wonder myself what we'd really be solving by 
making this change. I guess my reply to Morten at another place in this 
thread, where I talked about mixing line drawing and rectangle filling, 
shows that QPainter code typically needs to be written with scalability 
in mind.

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.

The drawback would be that code that explicitly wants to draw cosmetic 
lines would have to temporarily unset that render hint. Should we limit 
the render hint to only the 0-width magic value pens? That would 
probably solve all the style code, since there isn't really much code 
that does setCosmetic() on other pen widths (and when it does, it's 
probably a good sign that the programmer explicitly wants the pen to be 
cosmetic).

We actually already have this render hint, it's called 
QPainter::NonCosmeticDefaultPen. We'd just need to fix it to work, since 
it doesn't seem to be respected by the QPaintEngineEx based paint engines.

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?

--
Samuel



More information about the Development mailing list