summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-02-24 15:54:57 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 12:44:11 +0100
commit743e5ff9e37a7ea4b13c2620725c87a21e3b9975 (patch)
treeeec141358679804d367ac9e6cc0a1f3dd9ec0788 /src/widgets
parent5738bb533b97a9e19c18373286b157ee4d443532 (diff)
downloadqtquickcontrols-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/widgets')
-rw-r--r--src/widgets/qmessageboxhelper_p.h24
1 files changed, 23 insertions, 1 deletions
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) {