diff options
author | David Faure <david.faure@kdab.com> | 2017-01-09 00:10:42 +0100 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2017-01-11 15:15:39 +0000 |
commit | 2bb01172a76f14b1f57010b79207f6b9a9bf3f53 (patch) | |
tree | ff6e64b06e334f77951be90caf93c2ee94b26a90 | |
parent | 62882ad2fe3d9f70c876d7a51a5aab4118ce1ba3 (diff) |
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>
-rw-r--r-- | src/gui/text/qfont.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/text/qfont/tst_qfont.cpp | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 3b24039ea6..7f3ed3adaa 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -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 diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 06c0ba0819..2603206ab0 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -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 |