Bug #1803

WPainter.drawRect with PNG draws nothing if cosmetic (default) pen is used

Added by Boris Nagaev over 9 years ago. Updated over 9 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:



A pen with width 0 is a cosmetic pen, and is always rendered as 1 pixel width, regardless of transformations. Cosmetic pen is used by default. If PNG back-end is used, then cosmetic pen produces nothing for drawRect.

Wt 3.2.3


png-drawRect.cpp (1005 Bytes) png-drawRect.cpp Example. Comment out setPen to reproduce the bug. Boris Nagaev, 04/01/2013 02:45 PM
png-drawRect.cpp (1012 Bytes) png-drawRect.cpp Koen Deforche, 04/01/2013 10:14 PM

Updated by Koen Deforche over 9 years ago


I must admit, I got confused by the behavior of this test case, too. But it's not as bad as it seems.

There are two ways to get your test case to work as expected (see attached) :

  • use setRenderHint(WPainter::Antialiasing) to enable aliasing. You need aliasing because you are rendering a line which overlaps two pixels (this is because of how pixels are defined in the canvas, see the visual explanation at
  • or make sure a 1 pixel width line corresponds to real device pixels by offsetting it to the half of the line.

Probably you'll want to consider both things.

Admittedly, the default behaviour of WRasterImage, without anti-aliasing, is a bit unlucky and harsh and I'm open to suggestions on how to improve the documentation (I'm not sure it's straight forward to fix the behavior unless we would want to switch on antialiasing by default (it's 2013 after all).


Updated by Boris Nagaev over 9 years ago

Thanks for the explanation!

Also available in: Atom PDF