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

Samuel Rødal samuel.rodal at digia.com
Fri Oct 12 17:02:17 CEST 2012


On 10/12/2012 03:17 PM, Uwe Rathmann wrote:
> On Fri, 12 Oct 2012 12:21:30 +0000, Bache-Wiig Jens wrote:
>
>> After all what is the point of doing a
>> major version unless we don't even allow ourselves to change broken
>> defaults.
>
> There is nothing broken: it's a well defined API that behaves exactly
> like it is documented. Your suggestion is about modifying an illogical
> API.
>
> I don't know the reasons why the API was decided once the way it is - but
> it is so confusing, that I can't believe that it happened by accident
> ( being documented later ). My guess is that it was following some other
> system that did it this way.

Originally a 0-width pen was the only way to get the cosmetic pen 
behavior. Later on setCosmetic() was added to be able to have any pen 
width be cosmetic.

I guess the whole 0-width thing comes from X11, where 0 is a special 
value with the following documentation: "Thin lines (zero line-width) 
are one-pixel-wide lines drawn using an unspecified, device-dependent 
algorithm."

http://tronche.com/gui/x/xlib/GC/manipulating.html also contains this 
bit of documentation:

"A line-width of zero may differ from a line-width of one in which 
pixels are drawn. This permits the use of many manufacturers' line 
drawing hardware, which may run many times faster than the more 
precisely specified wide lines.

In general, drawing a thin line will be faster than drawing a wide line 
of width one. However, because of their different drawing algorithms, 
thin lines may not mix well aesthetically with wide lines. If it is 
desirable to obtain precise and uniform results across all displays, a 
client should always use a line-width of one rather than a line-width of 
zero."

So 0-width lines in X11 are not only implicitly cosmetic, but also have 
less strict guarantees when it comes to correctness, so that they can be 
optimized by custom hardware. I guess originally QPen simply mirrored 
this behavior, which is probably why as you noted 0-width pens are 
faster than 1-width pens with the X11 paint engine in 4.x.

Still, I agree with Jens that the API of having 0-width pens and 
cosmetic pens as separate concepts is confusing. If we wanted something 
akin to the 0-width concept of X11 it should rather have been a render 
hint saying that it's acceptable for the application to get less 
accurate line drawing in exchange for better performance. I'm not sure 
how valid that use case is these days though.

--
Samuel




More information about the Development mailing list