diff options
Diffstat (limited to 'src/widgets/dialogs/qmessagebox.cpp')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 6de952a1d3..99157747dd 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -64,6 +64,7 @@ #include <QtGui/qfont.h> #include <QtGui/qfontmetrics.h> #include <QtGui/qclipboard.h> +#include "private/qabstractbutton_p.h" #include <private/qdesktopwidget_p.h> #ifdef Q_OS_WIN @@ -492,9 +493,17 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role) { - Q_UNUSED(role); Q_Q(QMessageBox); - q->done(button); + if (button > QPlatformDialogHelper::LastButton) { + // It's a custom button, and the QPushButton in options is just a proxy + // for the button on the platform dialog. Simulate the user clicking it. + clickedButton = static_cast<QAbstractButton *>(options->customButton(button)->button); + Q_ASSERT(clickedButton); + clickedButton->click(); + q->done(role); + } else { + q->done(button); + } } /*! @@ -831,6 +840,8 @@ void QMessageBox::addButton(QAbstractButton *button, ButtonRole role) if (!button) return; removeButton(button); + d->options->addButton(button->text(), static_cast<QPlatformDialogHelper::ButtonRole>(role), + button); d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role); d->customButtonList.append(button); d->autoAddOkButton = false; @@ -1064,7 +1075,7 @@ void QMessageBoxPrivate::detectEscapeButton() or 0 if the user hit the \uicontrol Esc key and no \l{setEscapeButton()}{escape button} was set. - If exec() hasn't been called yet, returns 0. + If exec() hasn't been called yet, returns nullptr. Example: @@ -1082,7 +1093,7 @@ QAbstractButton *QMessageBox::clickedButton() const \since 4.2 Returns the button that should be the message box's - \l{QPushButton::setDefault()}{default button}. Returns 0 + \l{QPushButton::setDefault()}{default button}. Returns nullptr if no default button was set. \sa addButton(), QPushButton::setDefault() @@ -1489,8 +1500,6 @@ void QMessageBox::keyPressEvent(QKeyEvent *e) } /*! - \overload - Opens the dialog and connects its finished() or buttonClicked() signal to the slot specified by \a receiver and \a member. If the slot in \a member has a pointer for its first parameter the connection is to buttonClicked(), @@ -2678,7 +2687,11 @@ void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *) void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) { Q_Q(QMessageBox); - clickedButton = q->button(QMessageBox::StandardButton(code)); + QAbstractButton *button = q->button(QMessageBox::StandardButton(code)); + // If it was a custom button, a custom ID was used, so we won't get a valid pointer here. + // In that case, clickedButton has already been set in _q_buttonClicked. + if (button) + clickedButton = button; } /*! @@ -2730,7 +2743,7 @@ QPixmap QMessageBox::standardIcon(Icon icon) Shows the message box as a \l{QDialog#Modal Dialogs}{modal dialog}, blocking until the user closes it. - When using a QMessageBox with standard buttons, this functions returns a + When using a QMessageBox with standard buttons, this function returns a \l StandardButton value indicating the standard button that was clicked. When using QMessageBox with custom buttons, this function returns an opaque value; use clickedButton() to determine which button was clicked. |