Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.2
-
None
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