Use QFontMetrics::boundingRect() instead. QFontMetrics::width() does
not actually calculate the width of the bounding box and is mostly
useful for knowing where to draw text after a string, taking into
account bearings. Indeed, it has been renamed to
QFontMetrics::horizontalAdvance().
For the code touched in this commit, we want to center a string.
Either method would likely be fine, but it is more easy to
understand exactly what QFontMetrics::boundingRect() does.
This commit does change functionality, although it should not be
noticeable.
// draw the centered text
QFontMetrics fm(font);
- int w = fm.width(category);
+ int w = fm.boundingRect(category).width();
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
int y = opt.rect.y() + 3 * fm.ascent() / 2;
int left = x;
// draw the centered text
QFontMetrics fm(font);
- int w = fm.width(category);
+ int w = fm.boundingRect(category).width();
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
int y = opt.rect.y() + fm.ascent();
int left = x;