diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-02-24 15:54:57 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-28 12:44:11 +0100 |
commit | 743e5ff9e37a7ea4b13c2620725c87a21e3b9975 (patch) | |
tree | eec141358679804d367ac9e6cc0a1f3dd9ec0788 /src | |
parent | 5738bb533b97a9e19c18373286b157ee4d443532 (diff) | |
download | qtquickcontrols-743e5ff9e37a7ea4b13c2620725c87a21e3b9975.tar.gz |
MessageDialog: press escape or titlebar close button to dismiss
QMessageBox is a bit special compared to other dialogs, but we don't
need it to be so special in QtQuick.Dialogs. Also on OSX, cmd-period
will dismiss the dialog, regardless whether it is a QMessageBox or
the QML implementation.
Task-number: QTBUG-36227
Change-Id: I5dd43080600e9c3774990190bb401291efb8e742
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/dialogs/DefaultMessageDialog.qml | 4 | ||||
-rw-r--r-- | src/widgets/qmessageboxhelper_p.h | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/dialogs/DefaultMessageDialog.qml b/src/dialogs/DefaultMessageDialog.qml index 36ec507f..0b46f9f3 100644 --- a/src/dialogs/DefaultMessageDialog.qml +++ b/src/dialogs/DefaultMessageDialog.qml @@ -69,6 +69,10 @@ AbstractMessageDialog { case Qt.Key_C: detailedText.copy() break + case Qt.Key_Period: + if (Qt.platform.os === "osx") + reject() + break } else switch (event.key) { case Qt.Key_Escape: case Qt.Key_Back: diff --git a/src/widgets/qmessageboxhelper_p.h b/src/widgets/qmessageboxhelper_p.h index bf3eef32..cb02332b 100644 --- a/src/widgets/qmessageboxhelper_p.h +++ b/src/widgets/qmessageboxhelper_p.h @@ -58,6 +58,28 @@ QT_BEGIN_NAMESPACE +class QCloseableMessageBox : public QMessageBox +{ +public: + QCloseableMessageBox(QWidget *parent = 0) : QMessageBox(parent) { } + + void closeEvent(QCloseEvent *e) { + // QTBUG-36227: Bypass QMessageBox::closeEvent() + QDialog::closeEvent(e); + } + + void keyPressEvent(QKeyEvent *e) { + QMessageBox::keyPressEvent(e); + // QTBUG-36227: reject on escape or cmd-period even if there's no cancel button + if ((isVisible() && e->key() == Qt::Key_Escape) +#ifdef Q_OS_MAC + || (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) +#endif + ) + reject(); + } +}; + class QMessageBoxHelper : public QPlatformMessageDialogHelper { Q_OBJECT @@ -93,7 +115,7 @@ public: virtual void hide() { m_dialog.hide(); } - QMessageBox m_dialog; + QCloseableMessageBox m_dialog; public Q_SLOTS: void buttonClicked(QAbstractButton* button) { |