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

QPainter does not honor font's style name when it is created using QFont::fromString

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.2
    • None
    • macOS

    Description

      When a QFont is created using QFont::fromString, and this font is set to a QPainter, the styleName is not set correctly. This is because in QFont::fromString function, the styleName is directly updated without setting the QFont::StyleNameResolved flag.

      So when setting to QPainter, QFont::resolve function will overwrite the font's styleName

       
      Example:

      QFont font("Arial");
      font.setStyleName("Italic");
      
      QFont fontFromStr;
      fontFromStr.fromString(font.toString());
      
      QPainter painter(this);
      painter.setFont(fontFromStr);
      
      qDebug() << "<<<<< " << font.toString() << QFontInfo(font).styleName() << painter.fontInfo().styleName();
      
      // Output:
      // <<<<<  "Italic" "Italic" "Regular"

      Notice the styleName printed by painter's qfontinfo is incorrect

       

      I have attached a sample project which would give different styleName when QPainter:fontInfo().styleName() is called after setting the QFont created using QFont::fromString

      QFontInfoFromPainter.zip

      Attachments

        1. QFontInfoFromPainter.zip
          4 kB
          sivan nanthiran
        2. qtbug-100225.diff
          0.6 kB
          sivan nanthiran
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            nanthiran2005 sivan nanthiran
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes