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

QFontMetrics::width() returns different values in different versions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.8, 5.11, 5.12.0
    • GUI: Text handling
    • None
    • Linux/X11

    Description

      We were using Qt5.3 in our project, here all the strings in  QLabel are fitting perfectly.

      Now we planed to move to higher versions, but now we have problem with some Qt versions(Qt5.8/5.11/5.12) that strings are not fitting in QLabel, because here we are setting QFontMetrics::width() to QLabel width.

      As I debugged QFontMetrics::width() is returning different value in different Qt version.

      I am trying with below sample code to debug, I am using  QFontMetricsF to get the accurate value of text width.

       QFont font = ui->label->font();
       font.setPixelSize(38);
       QFontMetricsF fmf(font);
       qDebug() << fmf.width("ii");
      

        With the above code I got major different of width for below 3 strings(char i/l/T) .

      string Qt5.3 Qt5.8/5.11/5.12
      "ii"            16.1719      15.7188
      "ll" 15.75 15.7188
      "TT"            29.0313 28.9375

       

       I got to know that QFontMetrics::width() is deprecated in Qt5.11/5.12.

      I tried with QFontMetrics::horizontalAdvance() but it is also giving same result as width().

       

       

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            kumarh Harish Kumar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes