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

Samuel Rødal samuel.rodal at digia.com
Wed Oct 17 10:11:53 CEST 2012

On 10/11/2012 02:22 PM, Sorvig Morten wrote:
> On Oct 11, 2012, at 10:58 AM, Bache-Wiig Jens <Jens.Bache-Wiig at digia.com> wrote:
>> 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.
> I agree in general. I'm wondering if a 2 pixel-wide line for  QPen(Qt::black, 0.0) would be a better option in high-dpi mode - the user is expecting to "fill" one point. The result will look like a scaled pixmap, but won't have gaps.
> Morten

You mean a 1 "logical" pixel-wide line? ;)

But yeah, agreed, for high-dpi mode it will make sense that everything 
gets scaled by 2x2, both cosmetic and geometric lines, for the sake of 

"The result will look like a scaled pixmap" - well, an antialiased non 
axis aligned line will still look sharp, unlike a scaled pixmap.

"but won't have gaps", that depends, if you're mixing line drawing and 
rectangle filling you might have gaps.


painter->drawLine(0, 0, 10, 0);
painter->fillRect(0, 1, 10, 1, Qt::black);

Since lines and other outlines are centered on the pixel grid lines 
instead of in the pixel centers, if you scale this by 2x2 you will get 
the line filling the device rectangle starting at QPoint(0, -1) with a 
size QSize(20, 2), whereas the rect fills the device rectangle starting 
at QPoint(0, 2) with a size QSize(20, 2).

Thus, there would be a one pixel horizontal gap starting at QPoint(0, 1) 
with size QSize(20, 1). If the line is clipped by the widget it will 
visibly only be one pixel high, whereas the rectangle will be two pixels 

This way of mixing line drawing and filling in style code is therefore 
pretty evil, but unfortunately we do it in a lot of places. Most 
drawLine() calls in the style should really be replaced with calls to 

That's the curse of the 0.5 pixel offset between fills and strokes, and 
not writing the style code with scalability in mind.


More information about the Development mailing list