Be careful with QPainter::drawRect etc

Allen Winter winter at kde.org
Tue Sep 18 19:41:08 BST 2007


On Tuesday 18 September 2007 1:01:34 pm John Tapsell wrote:
> Hey all,
> 
>   I have tracked down a bugs in KFormula where the problem was that:
> 
> QPainterPath rect;
> rect.addRect(0, -baseLine(), width(), baseLine() );
> painter.drawPath( rect );
> 
> and
> 
> painter.drawRect(0, -baseLine(), width(), baseLine() );
> 
> Draw different rectangles.  The reason for this is that addRect takes
> reals, and drawRect takes int.  The drawRect thus loses precision, and
> draws incorrectly.
> 
> This is a very subtle and very nasty bug, as at 500% zoom, it's off by
> less than 10 pixels typically.
> 
> I have grepped the koffice source code and found hundreds of uses of
> drawRect, drawLine etc.  I'm sure that many of this are wrong.
> 
> Can we put a check for this use ebn?  There will be false positives,
> but I think we need to check all uses of this.
> 
> (same for drawLine, etc)
> 
Sounds like a job for a compiler.




More information about the kde-core-devel mailing list