]> git.lyx.org Git - features.git/commitdiff
Change a couple instances of QFontMetrics::width()
authorScott Kostyshak <skostysh@lyx.org>
Fri, 20 Mar 2020 13:39:51 +0000 (09:39 -0400)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:54 +0000 (15:48 +0200)
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.

src/frontends/qt/CategorizedCombo.cpp
src/frontends/qt/LayoutBox.cpp

index 4acae5bc3452324dc48ef233024c851f25b39dbf..319bcb0e9c1f522898048fdd73db8f38a9384e01 100644 (file)
@@ -244,7 +244,7 @@ void CCItemDelegate::drawCategoryHeader(QPainter * painter, QStyleOptionViewItem
 
        // 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;
index 7167eba3dcadbd61234c01d005710c5e7d19d2ea..01cb60e652eb8455038270b2a458d812221e136f 100644 (file)
@@ -275,7 +275,7 @@ void LayoutItemDelegate::drawCategoryHeader(QPainter * painter, QStyleOptionView
 
        // 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;