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 <richard.gustavsen@qt.io>
(cherry picked from commit efbcc80010005ee62d23f6814ec5c01310abf1df)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2022-07-07 13:39:13 +02:00 committed by Qt Cherry-pick Bot
parent 091cbe3e11
commit 4ef77e81b3

View File

@ -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<QPlatformFontDialogHelper *>(h)->setOptions(options);
Q_Q(QFontDialog);
auto *fontDialogHelper = static_cast<QPlatformFontDialogHelper *>(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();
}