QMessageBox: Reflect native dialog visibility via QWidget state
When a QMessageBox has a native backend we want the QWidget state of the dialog to still reflect whether the dialog is visible or not, as this is used by various features of QMessageBox, such as resolving the default escape button, for example. It is also key to being able to test the dialog, since the auto test relies on the observable widget state, and being able to send key events to the widget to trigger hiding of the dialog. The other QDialog subclasses with native dialog backends handle this by showing the native dialog, and then setting Qt::WA_DontShowOnScreen before calling QDialog::setVisible(), which results in the widget state being "correct", but not showing any widget-based dialog. QMessageBox however, did not implement setVisible(), and relied on the QDialog implementation, which does not contain similar logic. Ideally we want to clean up these overrides of setVisible(), and let QDialog handle Qt::WA_DontShowOnScreen for all native dialogs, but in the meantime we teach QMessageBox to do the same trick as the other dialog subclasses. Task-number: QTBUG-108153 Change-Id: I44c67cc9cd89660a703883bd57f351df70d7bdd3 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>bb10
parent
5827ee5ffc
commit
523496984c
|
|
@ -1556,6 +1556,23 @@ void QMessageBox::open(QObject *receiver, const char *member)
|
|||
QDialog::open();
|
||||
}
|
||||
|
||||
void QMessageBox::setVisible(bool visible)
|
||||
{
|
||||
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible)
|
||||
return;
|
||||
|
||||
Q_D(QMessageBox);
|
||||
if (d->canBeNativeDialog())
|
||||
d->setNativeDialogVisible(visible);
|
||||
|
||||
// Update WA_DontShowOnScreen based on whether the native dialog was shown,
|
||||
// so that QDialog::setVisible(visible) below updates the QWidget state correctly,
|
||||
// but skips showing the non-native version.
|
||||
setAttribute(Qt::WA_DontShowOnScreen, d->nativeDialogInUse);
|
||||
|
||||
QDialog::setVisible(visible);
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 4.5
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ public:
|
|||
using QDialog::open;
|
||||
void open(QObject *receiver, const char *member);
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
QList<QAbstractButton *> buttons() const;
|
||||
ButtonRole buttonRole(QAbstractButton *button) const;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue