From 4ef77e81b35dbae1a8c6b29ca703d701fc62fce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 7 Jul 2022 13:39:13 +0200 Subject: [PATCH] QFontDialog: Check if native dialog is in use before using A call to platformFontDialogHelper() will lazily create the helper, and is not enough to distinguish whether the helper is actually in use. The explicit nativeDialogInUse flag also takes properties like DontUseNativeDialog into account, which may be set after the dialog is first constructed. Fixes: QTBUG-104696 Change-Id: Ia00a39bba4aaae8c99ae0cdd6543c2e451f72ea6 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit efbcc80010005ee62d23f6814ec5c01310abf1df) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/dialogs/qfontdialog.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index bec99b4df70..26e9212a956 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -426,10 +426,12 @@ bool QFontDialog::eventFilter(QObject *o , QEvent *e) void QFontDialogPrivate::initHelper(QPlatformDialogHelper *h) { - QFontDialog *d = q_func(); - QObject::connect(h, SIGNAL(currentFontChanged(QFont)), d, SIGNAL(currentFontChanged(QFont))); - QObject::connect(h, SIGNAL(fontSelected(QFont)), d, SIGNAL(fontSelected(QFont))); - static_cast(h)->setOptions(options); + Q_Q(QFontDialog); + auto *fontDialogHelper = static_cast(h); + fontDialogHelper->setOptions(options); + fontDialogHelper->setCurrentFont(q->currentFont()); + QObject::connect(h, SIGNAL(currentFontChanged(QFont)), q, SIGNAL(currentFontChanged(QFont))); + QObject::connect(h, SIGNAL(fontSelected(QFont)), q, SIGNAL(fontSelected(QFont))); } void QFontDialogPrivate::helperPrepareShow(QPlatformDialogHelper *) @@ -788,8 +790,11 @@ void QFontDialog::setCurrentFont(const QFont &font) d->strikeout->setChecked(font.strikeOut()); d->underline->setChecked(font.underline()); d->updateFamilies(); - if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) - helper->setCurrentFont(font); + + if (d->nativeDialogInUse) { + if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) + helper->setCurrentFont(font); + } } /*! @@ -802,8 +807,11 @@ void QFontDialog::setCurrentFont(const QFont &font) QFont QFontDialog::currentFont() const { Q_D(const QFontDialog); - if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) - return helper->currentFont(); + + if (d->nativeDialogInUse) { + if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper()) + return helper->currentFont(); + } return d->sampleEdit->font(); }