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

QFontMetrics horizontalAdvance has rounding error

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.15.1
    • GUI: Font handling
    • None
    • Linux/Wayland, WebAssembly

    Description

      If I use font metrics to calculate the required width for text, the resulting width is depending on font, font size and platform not sufficient to avoid eliding as it seems to round the result down. The example below gives me 234 and 234.016 (Ubuntu Linux). If I use the latter with ceil everything is fine. If I use the former the text is being elided.

          QFont font("Arial", 20);
          QString text("Dies ist ein test text");
      
          const QFontMetrics fm(font);
          qDebug() << fm.elidedText( text, Qt::ElideRight, fm.horizontalAdvance(text) );
          const QFontMetricsF fmf(font);
          qDebug() << fmf.elidedText( text, Qt::ElideRight, fmf.horizontalAdvance(text) );
      

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            alexj Alexander Jährling
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes