QFontMetrics::boundingRect() is returning a rectangle width from the leftmost black pixel to the rightmost black pixel (Assuming a black pen).
The horizontalAdvance includes the whitespace that precedes/follows the end characters when rendered.
If you use QPainter::boundingRect() you will get a rectangle that contains the string neatly
The averageCharWidth() is that of all the glyphs in the font (not just the ones in your string), looks to be the rendered pixels only, and may be subject to rounding.
Bookmarks