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>
This commit is contained in:
Friedemann Kleint 2021-03-29 09:29:14 +02:00
parent d05118bf10
commit c10159a9a1

View File

@ -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);