diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-29 09:29:14 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-04-07 08:27:21 +0200 |
commit | c10159a9a1254992867242897adb19ae1c3c3c35 (patch) | |
tree | 73fae6098ced8d15f5ff7f6c13e2128fc1e53887 /examples | |
parent | d05118bf10e9a8ab419248a31d45a694a4622cb0 (diff) | |
download | qtbase-c10159a9a1254992867242897adb19ae1c3c3c35.tar.gz |
standarddialogs example: Fix font handling
The example crashed since it passed the font label text (which
receives the font key) to the QFont constructor taking the family list.
Use QFont::fromString() instead.
Pick-to: 6.0 6.1
Change-Id: I499fc9200b4d817b10c946a7b79ede4e7f7e69af
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/dialogs/standarddialogs/dialog.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index cd7e8085a2..7df24e06f6 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -388,8 +388,14 @@ void Dialog::setColor() void Dialog::setFont() { const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value()); + + const QString &description = fontLabel->text(); + QFont defaultFont; + if (!description.isEmpty()) + defaultFont.fromString(description); + bool ok; - QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this, "Select Font", options); + QFont font = QFontDialog::getFont(&ok, defaultFont, this, "Select Font", options); if (ok) { fontLabel->setText(font.key()); fontLabel->setFont(font); |