Make QDialog respect Qt::AA_DontUseNativeDialogs

QDialogs can be backed by native dialog helpers, and the choice of
whether to use a particular helper is a runtime decision, made
in QDialog::setVisible() via QDialogPrivate::canBeNativeDialog().

As the native dialogs may not always provide every feature of the
corresponding Qt dialog, or if the user wants a uniform look and
feel for their application (even if that breaks the platform UX),
there is a way to opt out, via the Qt::AA_DontUseNativeDialogs
attribute.

This attribute was checked by subclasses of QDialog/QDialogPrivate,
for example QFileDialog or QColorDialog, but not by the base class
implementation, which is being used by e.g. QMessageBox.

Ideally we'd reduce the amount of code duplication in this area,
by having subclasses such as QFileDialog and QColorDialog call the
base class implementations, but for now we add a similar check for
the attribute to the base class as we have in other leaf classes.

[ChangeLog][Widgets] QMessageBox now respects the Qt::AA_DontUseNativeDialogs
application attribute to opt out of native message boxes on
platforms where this is supported (iOS, Android).

Change-Id: I0080441ea8764e9d5fc62d7f2d7b8914a5844c28
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Tor Arne Vestbø 2022-10-26 14:24:13 +02:00
parent d59ae19c49
commit 971bd702ef
1 changed files with 3 additions and 0 deletions

View File

@ -98,6 +98,9 @@ QPlatformDialogHelper *QDialogPrivate::platformHelper() const
bool QDialogPrivate::canBeNativeDialog() const
{
if (QCoreApplication::testAttribute(Qt::AA_DontUseNativeDialogs))
return false;
QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);
QDialog *dialog = ncThis->q_func();
const int type = themeDialogType(dialog);