summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-06-10 07:30:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-20 22:02:00 +0200
commit3e87d7e81458a8622ae461ed03d881a17aade41c (patch)
tree50cdff0d9afa1c35f761ed571a6993fbec43c626 /src/widgets
parent16c47c3b343e2024cce3acd50f2dfe10ae5c40c7 (diff)
QMessageBox - make it possible to have a checkbox on the dialog
This (partly) solves Task-number: QTBUG-2450 Change-Id: Ie2280c87b96e72acc76e806a83c4e8cc0d4e4ee4 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp61
-rw-r--r--src/widgets/dialogs/qmessagebox.h4
2 files changed, 62 insertions, 3 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index f545d1ffd2..da5ec8dc8a 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -53,6 +53,7 @@
#include <QtWidgets/qgridlayout.h>
#include <QtWidgets/qdesktopwidget.h>
#include <QtWidgets/qpushbutton.h>
+#include <QtWidgets/qcheckbox.h>
#include <QtGui/qaccessible.h>
#include <QtGui/qicon.h>
#include <QtGui/qtextdocument.h>
@@ -198,7 +199,7 @@ class QMessageBoxPrivate : public QDialogPrivate
Q_DECLARE_PUBLIC(QMessageBox)
public:
- QMessageBoxPrivate() : escapeButton(0), defaultButton(0), clickedButton(0), detailsButton(0),
+ QMessageBoxPrivate() : escapeButton(0), defaultButton(0), checkbox(0), clickedButton(0), detailsButton(0),
#ifndef QT_NO_TEXTEDIT
detailsText(0),
#endif
@@ -248,6 +249,7 @@ public:
QList<QAbstractButton *> customButtonList;
QAbstractButton *escapeButton;
QPushButton *defaultButton;
+ QCheckBox *checkbox;
QAbstractButton *clickedButton;
DetailButton *detailsButton;
#ifndef QT_NO_TEXTEDIT
@@ -317,8 +319,16 @@ void QMessageBoxPrivate::setupLayout()
#endif
grid->addWidget(informativeLabel, 1, hasIcon ? 2 : 1, 1, 1);
}
+ if (checkbox) {
+ grid->addWidget(checkbox, informativeLabel ? 2 : 1, hasIcon ? 2 : 1, 1, 1, Qt::AlignLeft);
#ifdef Q_OS_MAC
- grid->addWidget(buttonBox, 3, hasIcon ? 2 : 1, 1, 1);
+ grid->addItem(new QSpacerItem(1, 15, QSizePolicy::Fixed, QSizePolicy::Fixed), grid->rowCount(), 0);
+#else
+ grid->addItem(new QSpacerItem(1, 7, QSizePolicy::Fixed, QSizePolicy::Fixed), grid->rowCount(), 0);
+#endif
+ }
+#ifdef Q_OS_MAC
+ grid->addWidget(buttonBox, grid->rowCount(), hasIcon ? 2 : 1, 1, 1);
grid->setMargin(0);
grid->setVerticalSpacing(8);
grid->setHorizontalSpacing(0);
@@ -326,7 +336,7 @@ void QMessageBoxPrivate::setupLayout()
grid->setRowStretch(1, 100);
grid->setRowMinimumHeight(2, 6);
#else
- grid->addWidget(buttonBox, 2, 0, 1, grid->columnCount());
+ grid->addWidget(buttonBox, grid->rowCount(), 0, 1, grid->columnCount());
#endif
if (detailsText)
grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount());
@@ -1127,6 +1137,51 @@ void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)
setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));
}
+/*! \since 5.2
+
+ Sets the checkbox \a cb on the message dialog. The message box takes ownership of the checkbox.
+ The argument \a cb can be 0 to remove an existing checkbox from the message box.
+
+ \sa checkBox()
+*/
+
+void QMessageBox::setCheckBox(QCheckBox *cb)
+{
+ Q_D(QMessageBox);
+
+ if (cb == d->checkbox)
+ return;
+
+ if (d->checkbox) {
+ d->checkbox->hide();
+ layout()->removeWidget(d->checkbox);
+ if (d->checkbox->parentWidget() == this) {
+ d->checkbox->setParent(0);
+ d->checkbox->deleteLater();
+ }
+ }
+ d->checkbox = cb;
+ if (d->checkbox) {
+ QSizePolicy sp = d->checkbox->sizePolicy();
+ sp.setHorizontalPolicy(QSizePolicy::MinimumExpanding);
+ d->checkbox->setSizePolicy(sp);
+ }
+ d->setupLayout();
+}
+
+
+/*! \since 5.2
+
+ Returns the checkbox shown on the dialog. This is 0 if no checkbox is set.
+ \sa setCheckBox()
+*/
+
+QCheckBox* QMessageBox::checkBox() const
+{
+ Q_D(const QMessageBox);
+ return d->checkbox;
+}
+
/*!
\property QMessageBox::text
\brief the message box text to be displayed.
diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h
index c7c42b1e7a..58be13426c 100644
--- a/src/widgets/dialogs/qmessagebox.h
+++ b/src/widgets/dialogs/qmessagebox.h
@@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
class QLabel;
class QMessageBoxPrivate;
class QAbstractButton;
+class QCheckBox;
class Q_WIDGETS_EXPORT QMessageBox : public QDialog
{
@@ -188,6 +189,9 @@ public:
void setTextInteractionFlags(Qt::TextInteractionFlags flags);
Qt::TextInteractionFlags textInteractionFlags() const;
+ void setCheckBox(QCheckBox *cb);
+ QCheckBox* checkBox() const;
+
static StandardButton information(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);