summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-03-29 09:29:14 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-07 09:42:31 +0000
commit35e6ef63950f4bd745a69c1a623e0de3afcf82ae (patch)
tree59f70b4d177774da186c490ddd6ee410156fe712 /examples/widgets
parent65760c077df20a3ab7c1492f7f0b2a6c2a599b28 (diff)
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. Change-Id: I499fc9200b4d817b10c946a7b79ede4e7f7e69af Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit c10159a9a1254992867242897adb19ae1c3c3c35) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp8
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);