Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89168

QFontMetrics::boundingRect() does not account for letter spacing in width

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.1
    • GUI: Font handling
    • None
    • Linux/X11

    Description

      I have some text drawn using a QFont where I setLetterSpacing() and want to get the width of the rendered text, but the letter spacing does not seem to affect the computed width, but does affect the rendered text.

      I have an example snippet below which I compiled against Qt 5.15.1. I would expect the computed width for the two fonts to be different, but both return 51 for me.

      #include <QApplication>
      #include <QFont>
      #include <QFontMetrics>
      #include <iostream>
      
      int main(int argc, char *argv[])
      {
        QApplication a(argc, argv);
      
        const QString text = "Example";
      
        QFont font;
        QFontMetrics fontMetrics( font );
      
        QFont spacedFont;
        spacedFont.setLetterSpacing( QFont::AbsoluteSpacing, 20 );
        QFontMetrics spacedFontMetrics( spacedFont );
      
        std::cerr << "Default font width = " <<
                     fontMetrics.boundingRect( text ).width() << std::endl;
        std::cerr << "Spaced font width = " <<
                     spacedFontMetrics.boundingRect( text ).width() << std::endl;
      
        return 0;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            chris857 chris857
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes