QFont: fix fromString(toString()) when application font has styleName
The style name needs to be cleared if not present in the string, otherwise the style name from qApp->font() (which propagates to any default-constructed QFont) remains. Change-Id: I9b6522a39a38526cced8a11ed02ae32582026480 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
This commit is contained in:
parent
62882ad2fe
commit
2bb01172a7
@ -2077,6 +2077,8 @@ bool QFont::fromString(const QString &descrip)
|
||||
setFixedPitch(l[8].toInt());
|
||||
if (count == 11)
|
||||
d->request.styleName = l[10].toString();
|
||||
else
|
||||
d->request.styleName.clear();
|
||||
}
|
||||
|
||||
if (count >= 9 && !d->request.fixedPitch) // assume 'false' fixedPitch equals default
|
||||
|
@ -63,6 +63,7 @@ private slots:
|
||||
void defaultFamily_data();
|
||||
void defaultFamily();
|
||||
void toAndFromString();
|
||||
void fromStringWithoutStyleName();
|
||||
|
||||
void sharing();
|
||||
};
|
||||
@ -561,6 +562,19 @@ void tst_QFont::toAndFromString()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QFont::fromStringWithoutStyleName()
|
||||
{
|
||||
QFont font1;
|
||||
font1.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular");
|
||||
|
||||
QFont font2 = font1;
|
||||
const QString str = "Times,16,-1,5,50,0,0,0,0,0";
|
||||
font2.fromString(str);
|
||||
|
||||
QCOMPARE(font2.toString(), str);
|
||||
}
|
||||
|
||||
|
||||
void tst_QFont::sharing()
|
||||
{
|
||||
// QFontCache references the engineData
|
||||
|
Loading…
Reference in New Issue
Block a user