View Full Version : Why must I pad boundingRect() by 7 pixels

10th September 2009, 08:31

I have a clipping/redraw problem with a custom graphicsItem that I draw using the following painter:

ypos = xpos = 0;
painter->drawLine( width/2, ypos, width/2, height );
painter->drawRect(xpos, ypos, width, height);

and an overloaded boundingRect call

return QRectF(xpos,ypos,width+wadjust,height+hadjust);

I have found that if I pass an object over this graphicsItem (crosshairs in my scene) I get some clipping. If I set the wadjust to 7 (the magic number), I see no clipping. Anything below that I get the clipping but the clipping is fixed by passing the crosshairs back over the object in the opposite direction or by resizing the scene (complete redraw).

I didn't think the painter pen added width to the drawRect() unless the rectangle was stroked. Any ideas?

I also remember seeing something in the docs that described how objects are drawn and how the outline pixels are placed around an object but can no longer find that explanation. Anyone know what I'm talking about?


10th September 2009, 08:39
Could you prepare a minimal compilable example reproducing the problem?

10th September 2009, 08:46
well it's kind of messy at the moment and it needs to load data to draw the widgets on the scene (2d stock chart). I guess I could try to hack it up but is there anything else I could answer to help?

10th September 2009, 15:07
Do you know how many pixels the pen adds to a drawRect?

painter->pen()->width() returns 0