0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtGui/qmessagebox.h>
|
|
43 |
|
|
44 |
#ifndef QT_NO_MESSAGEBOX
|
|
45 |
|
|
46 |
#include <QtGui/qdialogbuttonbox.h>
|
|
47 |
#include "private/qlabel_p.h"
|
|
48 |
#include "private/qapplication_p.h"
|
|
49 |
#include <QtCore/qlist.h>
|
|
50 |
#include <QtCore/qdebug.h>
|
|
51 |
#include <QtGui/qstyle.h>
|
|
52 |
#include <QtGui/qstyleoption.h>
|
|
53 |
#include <QtGui/qgridlayout.h>
|
|
54 |
#include <QtGui/qdesktopwidget.h>
|
|
55 |
#include <QtGui/qpushbutton.h>
|
|
56 |
#include <QtGui/qaccessible.h>
|
|
57 |
#include <QtGui/qicon.h>
|
|
58 |
#include <QtGui/qtextdocument.h>
|
|
59 |
#include <QtGui/qapplication.h>
|
|
60 |
#include <QtGui/qtextedit.h>
|
|
61 |
#include <QtGui/qmenu.h>
|
|
62 |
#include "qdialog_p.h"
|
|
63 |
#include <QtGui/qfont.h>
|
|
64 |
#include <QtGui/qfontmetrics.h>
|
|
65 |
#include <QtGui/qclipboard.h>
|
|
66 |
|
|
67 |
#ifdef Q_WS_WINCE
|
|
68 |
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
|
|
69 |
extern bool qt_wince_is_smartphone();//defined in qguifunctions_wince.cpp
|
|
70 |
extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
|
|
71 |
|
|
72 |
#include "qguifunctions_wince.h"
|
|
73 |
#endif
|
|
74 |
|
|
75 |
QT_BEGIN_NAMESPACE
|
|
76 |
|
|
77 |
enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,
|
|
78 |
Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,
|
|
79 |
NewButtonMask = 0xFFFFFC00 };
|
|
80 |
|
|
81 |
enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 };
|
|
82 |
#ifndef QT_NO_TEXTEDIT
|
|
83 |
class QMessageBoxDetailsText : public QWidget
|
|
84 |
{
|
|
85 |
public:
|
|
86 |
class TextEdit : public QTextEdit
|
|
87 |
{
|
|
88 |
public:
|
|
89 |
TextEdit(QWidget *parent=0) : QTextEdit(parent) { }
|
|
90 |
void contextMenuEvent(QContextMenuEvent * e)
|
|
91 |
{
|
|
92 |
#ifndef QT_NO_CONTEXTMENU
|
|
93 |
QMenu *menu = createStandardContextMenu();
|
|
94 |
menu->exec(e->globalPos());
|
|
95 |
delete menu;
|
|
96 |
#else
|
|
97 |
Q_UNUSED(e);
|
|
98 |
#endif
|
|
99 |
}
|
|
100 |
};
|
|
101 |
|
|
102 |
QMessageBoxDetailsText(QWidget *parent=0)
|
|
103 |
: QWidget(parent)
|
|
104 |
{
|
|
105 |
QVBoxLayout *layout = new QVBoxLayout;
|
|
106 |
layout->setMargin(0);
|
|
107 |
QFrame *line = new QFrame(this);
|
|
108 |
line->setFrameShape(QFrame::HLine);
|
|
109 |
line->setFrameShadow(QFrame::Sunken);
|
|
110 |
layout->addWidget(line);
|
|
111 |
textEdit = new TextEdit();
|
|
112 |
textEdit->setFixedHeight(100);
|
|
113 |
textEdit->setFocusPolicy(Qt::NoFocus);
|
|
114 |
textEdit->setReadOnly(true);
|
|
115 |
layout->addWidget(textEdit);
|
|
116 |
setLayout(layout);
|
|
117 |
}
|
|
118 |
void setText(const QString &text) { textEdit->setPlainText(text); }
|
|
119 |
QString text() const { return textEdit->toPlainText(); }
|
|
120 |
QString label(DetailButtonLabel label)
|
|
121 |
{ return label == ShowLabel ? QMessageBox::tr("Show Details...")
|
|
122 |
: QMessageBox::tr("Hide Details..."); }
|
|
123 |
private:
|
|
124 |
TextEdit *textEdit;
|
|
125 |
};
|
|
126 |
#endif // QT_NO_TEXTEDIT
|
|
127 |
|
|
128 |
class QMessageBoxPrivate : public QDialogPrivate
|
|
129 |
{
|
|
130 |
Q_DECLARE_PUBLIC(QMessageBox)
|
|
131 |
|
|
132 |
public:
|
|
133 |
QMessageBoxPrivate() : escapeButton(0), defaultButton(0), clickedButton(0), detailsButton(0),
|
|
134 |
#ifndef QT_NO_TEXTEDIT
|
|
135 |
detailsText(0),
|
|
136 |
#endif
|
|
137 |
compatMode(false), autoAddOkButton(true),
|
|
138 |
detectedEscapeButton(0), informativeLabel(0) { }
|
|
139 |
|
|
140 |
void init(const QString &title = QString(), const QString &text = QString());
|
|
141 |
void _q_buttonClicked(QAbstractButton *);
|
|
142 |
|
|
143 |
QAbstractButton *findButton(int button0, int button1, int button2, int flags);
|
|
144 |
void addOldButtons(int button0, int button1, int button2);
|
|
145 |
|
|
146 |
QAbstractButton *abstractButtonForId(int id) const;
|
|
147 |
int execReturnCode(QAbstractButton *button);
|
|
148 |
|
|
149 |
void detectEscapeButton();
|
|
150 |
void updateSize();
|
|
151 |
int layoutMinimumWidth();
|
|
152 |
void retranslateStrings();
|
|
153 |
|
|
154 |
#ifdef Q_WS_WINCE
|
|
155 |
void hideSpecial();
|
|
156 |
#endif
|
|
157 |
|
|
158 |
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
|
159 |
const QString &title, const QString &text,
|
|
160 |
int button0, int button1, int button2);
|
|
161 |
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
|
162 |
const QString &title, const QString &text,
|
|
163 |
const QString &button0Text,
|
|
164 |
const QString &button1Text,
|
|
165 |
const QString &button2Text,
|
|
166 |
int defaultButtonNumber,
|
|
167 |
int escapeButtonNumber);
|
|
168 |
|
|
169 |
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,
|
|
170 |
QMessageBox::Icon icon, const QString& title, const QString& text,
|
|
171 |
QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
|
|
172 |
|
|
173 |
static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb);
|
|
174 |
|
|
175 |
QLabel *label;
|
|
176 |
QMessageBox::Icon icon;
|
|
177 |
QLabel *iconLabel;
|
|
178 |
QDialogButtonBox *buttonBox;
|
|
179 |
QList<QAbstractButton *> customButtonList;
|
|
180 |
QAbstractButton *escapeButton;
|
|
181 |
QPushButton *defaultButton;
|
|
182 |
QAbstractButton *clickedButton;
|
|
183 |
QPushButton *detailsButton;
|
|
184 |
#ifndef QT_NO_TEXTEDIT
|
|
185 |
QMessageBoxDetailsText *detailsText;
|
|
186 |
#endif
|
|
187 |
bool compatMode;
|
|
188 |
bool autoAddOkButton;
|
|
189 |
QAbstractButton *detectedEscapeButton;
|
|
190 |
QLabel *informativeLabel;
|
|
191 |
QPointer<QObject> receiverToDisconnectOnClose;
|
|
192 |
QByteArray memberToDisconnectOnClose;
|
|
193 |
QByteArray signalToDisconnectOnClose;
|
|
194 |
};
|
|
195 |
|
|
196 |
void QMessageBoxPrivate::init(const QString &title, const QString &text)
|
|
197 |
{
|
|
198 |
Q_Q(QMessageBox);
|
|
199 |
|
|
200 |
label = new QLabel;
|
|
201 |
label->setObjectName(QLatin1String("qt_msgbox_label"));
|
|
202 |
label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, q)));
|
|
203 |
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
|
204 |
label->setOpenExternalLinks(true);
|
|
205 |
#if defined(Q_WS_MAC)
|
|
206 |
label->setContentsMargins(16, 0, 0, 0);
|
|
207 |
#elif !defined(Q_WS_QWS)
|
|
208 |
label->setContentsMargins(2, 0, 0, 0);
|
|
209 |
label->setIndent(9);
|
|
210 |
#endif
|
|
211 |
icon = QMessageBox::NoIcon;
|
|
212 |
iconLabel = new QLabel;
|
|
213 |
iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label"));
|
|
214 |
iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
215 |
|
|
216 |
buttonBox = new QDialogButtonBox;
|
|
217 |
buttonBox->setObjectName(QLatin1String("qt_msgbox_buttonbox"));
|
|
218 |
buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, q));
|
|
219 |
QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)),
|
|
220 |
q, SLOT(_q_buttonClicked(QAbstractButton*)));
|
|
221 |
|
|
222 |
QGridLayout *grid = new QGridLayout;
|
|
223 |
#ifndef Q_WS_MAC
|
|
224 |
grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop);
|
|
225 |
grid->addWidget(label, 0, 1, 1, 1);
|
|
226 |
// -- leave space for information label --
|
|
227 |
grid->addWidget(buttonBox, 2, 0, 1, 2);
|
|
228 |
#else
|
|
229 |
grid->setMargin(0);
|
|
230 |
grid->setVerticalSpacing(8);
|
|
231 |
grid->setHorizontalSpacing(0);
|
|
232 |
q->setContentsMargins(24, 15, 24, 20);
|
|
233 |
grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignLeft);
|
|
234 |
grid->addWidget(label, 0, 1, 1, 1);
|
|
235 |
// -- leave space for information label --
|
|
236 |
grid->setRowStretch(1, 100);
|
|
237 |
grid->setRowMinimumHeight(2, 6);
|
|
238 |
grid->addWidget(buttonBox, 3, 1, 1, 1);
|
|
239 |
#endif
|
|
240 |
|
|
241 |
grid->setSizeConstraint(QLayout::SetNoConstraint);
|
|
242 |
q->setLayout(grid);
|
|
243 |
|
|
244 |
if (!title.isEmpty() || !text.isEmpty()) {
|
|
245 |
q->setWindowTitle(title);
|
|
246 |
q->setText(text);
|
|
247 |
}
|
|
248 |
q->setModal(true);
|
|
249 |
|
|
250 |
#ifdef Q_WS_MAC
|
|
251 |
QFont f = q->font();
|
|
252 |
f.setBold(true);
|
|
253 |
label->setFont(f);
|
|
254 |
#endif
|
|
255 |
retranslateStrings();
|
|
256 |
}
|
|
257 |
|
|
258 |
int QMessageBoxPrivate::layoutMinimumWidth()
|
|
259 |
{
|
|
260 |
layout->activate();
|
|
261 |
return layout->totalMinimumSize().width();
|
|
262 |
}
|
|
263 |
|
|
264 |
void QMessageBoxPrivate::updateSize()
|
|
265 |
{
|
|
266 |
Q_Q(QMessageBox);
|
|
267 |
|
|
268 |
if (!q->isVisible())
|
|
269 |
return;
|
|
270 |
|
|
271 |
QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
|
|
272 |
#if defined(Q_WS_QWS) || defined(Q_WS_WINCE) || defined(Q_OS_SYMBIAN)
|
|
273 |
// the width of the screen, less the window border.
|
|
274 |
int hardLimit = screenSize.width() - (q->frameGeometry().width() - q->geometry().width());
|
|
275 |
#else
|
|
276 |
int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
|
|
277 |
// on small screens allows the messagebox be the same size as the screen
|
|
278 |
if (screenSize.width() <= 1024)
|
|
279 |
hardLimit = screenSize.width();
|
|
280 |
#endif
|
|
281 |
#ifdef Q_WS_MAC
|
|
282 |
int softLimit = qMin(screenSize.width()/2, 420);
|
|
283 |
#elif defined(Q_WS_QWS)
|
|
284 |
int softLimit = qMin(hardLimit, 500);
|
|
285 |
#else
|
|
286 |
// note: ideally on windows, hard and soft limits but it breaks compat
|
|
287 |
#ifndef Q_WS_WINCE
|
|
288 |
int softLimit = qMin(screenSize.width()/2, 500);
|
|
289 |
#else
|
|
290 |
int softLimit = qMin(screenSize.width() * 3 / 4, 500);
|
|
291 |
#endif //Q_WS_WINCE
|
|
292 |
#endif
|
|
293 |
|
|
294 |
if (informativeLabel)
|
|
295 |
informativeLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
|
296 |
|
|
297 |
label->setWordWrap(false); // makes the label return min size
|
|
298 |
int width = layoutMinimumWidth();
|
|
299 |
|
|
300 |
if (width > softLimit) {
|
|
301 |
label->setWordWrap(true);
|
|
302 |
width = qMax(softLimit, layoutMinimumWidth());
|
|
303 |
|
|
304 |
if (width > hardLimit) {
|
|
305 |
label->d_func()->ensureTextControl();
|
|
306 |
if (QTextControl *control = label->d_func()->control) {
|
|
307 |
QTextOption opt = control->document()->defaultTextOption();
|
|
308 |
opt.setWrapMode(QTextOption::WrapAnywhere);
|
|
309 |
control->document()->setDefaultTextOption(opt);
|
|
310 |
}
|
|
311 |
width = hardLimit;
|
|
312 |
}
|
|
313 |
#ifdef Q_WS_S60
|
|
314 |
// in S60 portait messageBoxes should always occupy maximum width
|
|
315 |
if (QApplication::desktop()->size().height() > QApplication::desktop()->size().width()){
|
|
316 |
width = hardLimit;
|
|
317 |
} else {
|
|
318 |
// in landscape the messageBoxes should be of same width as in portrait
|
|
319 |
width = qMin(QApplication::desktop()->size().height(), hardLimit);
|
|
320 |
}
|
|
321 |
#endif
|
|
322 |
}
|
|
323 |
|
|
324 |
if (informativeLabel) {
|
|
325 |
label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
|
326 |
QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
327 |
policy.setHeightForWidth(true);
|
|
328 |
informativeLabel->setSizePolicy(policy);
|
|
329 |
width = qMax(width, layoutMinimumWidth());
|
|
330 |
if (width > hardLimit) { // longest word is really big, so wrap anywhere
|
|
331 |
informativeLabel->d_func()->ensureTextControl();
|
|
332 |
if (QTextControl *control = informativeLabel->d_func()->control) {
|
|
333 |
QTextOption opt = control->document()->defaultTextOption();
|
|
334 |
opt.setWrapMode(QTextOption::WrapAnywhere);
|
|
335 |
control->document()->setDefaultTextOption(opt);
|
|
336 |
}
|
|
337 |
width = hardLimit;
|
|
338 |
}
|
|
339 |
policy.setHeightForWidth(label->wordWrap());
|
|
340 |
label->setSizePolicy(policy);
|
|
341 |
}
|
|
342 |
|
|
343 |
QFontMetrics fm(QApplication::font("QWorkspaceTitleBar"));
|
|
344 |
int windowTitleWidth = qMin(fm.width(q->windowTitle()) + 50, hardLimit);
|
|
345 |
if (windowTitleWidth > width)
|
|
346 |
width = windowTitleWidth;
|
|
347 |
|
|
348 |
layout->activate();
|
|
349 |
int height = (layout->hasHeightForWidth())
|
|
350 |
? layout->totalHeightForWidth(width)
|
|
351 |
: layout->totalMinimumSize().height();
|
|
352 |
q->setFixedSize(width, height);
|
|
353 |
QCoreApplication::removePostedEvents(q, QEvent::LayoutRequest);
|
|
354 |
}
|
|
355 |
|
|
356 |
|
|
357 |
#ifdef Q_WS_WINCE
|
|
358 |
/*!
|
|
359 |
\internal
|
|
360 |
Hides special buttons which are rather shown in the title bar
|
|
361 |
on WinCE, to conserve screen space.
|
|
362 |
*/
|
|
363 |
|
|
364 |
void QMessageBoxPrivate::hideSpecial()
|
|
365 |
{
|
|
366 |
Q_Q(QMessageBox);
|
|
367 |
QList<QPushButton*> list = qFindChildren<QPushButton*>(q);
|
|
368 |
for (int i=0; i<list.size(); ++i) {
|
|
369 |
QPushButton *pb = list.at(i);
|
|
370 |
QString text = pb->text();
|
|
371 |
text.remove(QChar::fromLatin1('&'));
|
|
372 |
if (text == QApplication::translate("QMessageBox", "OK" ))
|
|
373 |
pb->setFixedSize(0,0);
|
|
374 |
}
|
|
375 |
}
|
|
376 |
#endif
|
|
377 |
|
|
378 |
static int oldButton(int button)
|
|
379 |
{
|
|
380 |
switch (button & QMessageBox::ButtonMask) {
|
|
381 |
case QMessageBox::Ok:
|
|
382 |
return Old_Ok;
|
|
383 |
case QMessageBox::Cancel:
|
|
384 |
return Old_Cancel;
|
|
385 |
case QMessageBox::Yes:
|
|
386 |
return Old_Yes;
|
|
387 |
case QMessageBox::No:
|
|
388 |
return Old_No;
|
|
389 |
case QMessageBox::Abort:
|
|
390 |
return Old_Abort;
|
|
391 |
case QMessageBox::Retry:
|
|
392 |
return Old_Retry;
|
|
393 |
case QMessageBox::Ignore:
|
|
394 |
return Old_Ignore;
|
|
395 |
case QMessageBox::YesToAll:
|
|
396 |
return Old_YesAll;
|
|
397 |
case QMessageBox::NoToAll:
|
|
398 |
return Old_NoAll;
|
|
399 |
default:
|
|
400 |
return 0;
|
|
401 |
}
|
|
402 |
}
|
|
403 |
|
|
404 |
int QMessageBoxPrivate::execReturnCode(QAbstractButton *button)
|
|
405 |
{
|
|
406 |
int ret = buttonBox->standardButton(button);
|
|
407 |
if (ret == QMessageBox::NoButton) {
|
|
408 |
ret = customButtonList.indexOf(button); // if button == 0, correctly sets ret = -1
|
|
409 |
} else if (compatMode) {
|
|
410 |
ret = oldButton(ret);
|
|
411 |
}
|
|
412 |
return ret;
|
|
413 |
}
|
|
414 |
|
|
415 |
void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button)
|
|
416 |
{
|
|
417 |
Q_Q(QMessageBox);
|
|
418 |
#ifndef QT_NO_TEXTEDIT
|
|
419 |
if (detailsButton && detailsText && button == detailsButton) {
|
|
420 |
detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
|
|
421 |
detailsText->setHidden(!detailsText->isHidden());
|
|
422 |
updateSize();
|
|
423 |
} else
|
|
424 |
#endif
|
|
425 |
{
|
|
426 |
clickedButton = button;
|
|
427 |
q->done(execReturnCode(button)); // does not trigger closeEvent
|
|
428 |
emit q->buttonClicked(button);
|
|
429 |
|
|
430 |
if (receiverToDisconnectOnClose) {
|
|
431 |
QObject::disconnect(q, signalToDisconnectOnClose, receiverToDisconnectOnClose,
|
|
432 |
memberToDisconnectOnClose);
|
|
433 |
receiverToDisconnectOnClose = 0;
|
|
434 |
}
|
|
435 |
signalToDisconnectOnClose.clear();
|
|
436 |
memberToDisconnectOnClose.clear();
|
|
437 |
}
|
|
438 |
}
|
|
439 |
|
|
440 |
/*!
|
|
441 |
\class QMessageBox
|
|
442 |
|
|
443 |
\brief The QMessageBox class provides a modal dialog for informing
|
|
444 |
the user or for asking the user a question and receiving an answer.
|
|
445 |
|
|
446 |
\ingroup standard-dialogs
|
|
447 |
|
|
448 |
|
|
449 |
A message box displays a primary \l{QMessageBox::text}{text} to
|
|
450 |
alert the user to a situation, an \l{QMessageBox::informativeText}
|
|
451 |
{informative text} to further explain the alert or to ask the user
|
|
452 |
a question, and an optional \l{QMessageBox::detailedText}
|
|
453 |
{detailed text} to provide even more data if the user requests
|
|
454 |
it. A message box can also display an \l{QMessageBox::icon} {icon}
|
|
455 |
and \l{QMessageBox::standardButtons} {standard buttons} for
|
|
456 |
accepting a user response.
|
|
457 |
|
|
458 |
Two APIs for using QMessageBox are provided, the property-based
|
|
459 |
API, and the static functions. Calling one of the static functions
|
|
460 |
is the simpler approach, but it is less flexible than using the
|
|
461 |
property-based API, and the result is less informative. Using the
|
|
462 |
property-based API is recommended.
|
|
463 |
|
|
464 |
\section1 The Property-based API
|
|
465 |
|
|
466 |
To use the property-based API, construct an instance of
|
|
467 |
QMessageBox, set the desired properties, and call exec() to show
|
|
468 |
the message. The simplest configuration is to set only the
|
|
469 |
\l{QMessageBox::text} {message text} property.
|
|
470 |
|
|
471 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 5
|
|
472 |
|
|
473 |
The user must click the \gui{OK} button to dismiss the message
|
|
474 |
box. The rest of the GUI is blocked until the message box is
|
|
475 |
dismissed.
|
|
476 |
|
|
477 |
\image msgbox1.png
|
|
478 |
|
|
479 |
A better approach than just alerting the user to an event is to
|
|
480 |
also ask the user what to do about it. Store the question in the
|
|
481 |
\l{QMessageBox::informativeText} {informative text} property, and
|
|
482 |
set the \l{QMessageBox::standardButtons} {standard buttons}
|
|
483 |
property to the set of buttons you want as the set of user
|
|
484 |
responses. The buttons are specified by combining values from
|
|
485 |
StandardButtons using the bitwise OR operator. The display order
|
|
486 |
for the buttons is platform-dependent. For example, on Windows,
|
|
487 |
\gui{Save} is displayed to the left of \gui{Cancel}, whereas on
|
|
488 |
Mac OS, the order is reversed.
|
|
489 |
|
|
490 |
Mark one of your standard buttons to be your
|
|
491 |
\l{QMessageBox::defaultButton()} {default button}.
|
|
492 |
|
|
493 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 6
|
|
494 |
|
|
495 |
This is the approach recommended in the
|
|
496 |
\l{http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGWindows/chapter_18_section_7.html}
|
|
497 |
{Mac OS X Guidlines}. Similar guidlines apply for the other
|
|
498 |
platforms, but note the different ways the
|
|
499 |
\l{QMessageBox::informativeText} {informative text} is handled for
|
|
500 |
different platforms.
|
|
501 |
|
|
502 |
\image msgbox2.png
|
|
503 |
|
|
504 |
The exec() slot returns the StandardButtons value of the button
|
|
505 |
that was clicked.
|
|
506 |
|
|
507 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 7
|
|
508 |
|
|
509 |
To give the user more information to help him answer the question,
|
|
510 |
set the \l{QMessageBox::detailedText} {detailed text} property. If
|
|
511 |
the \l{QMessageBox::detailedText} {detailed text} property is set,
|
|
512 |
the \gui{Show Details...} button will be shown.
|
|
513 |
|
|
514 |
\image msgbox3.png
|
|
515 |
|
|
516 |
Clicking the \gui{Show Details...} button displays the detailed text.
|
|
517 |
|
|
518 |
\image msgbox4.png
|
|
519 |
|
|
520 |
\section2 Rich Text and the Text Format Property
|
|
521 |
|
|
522 |
The \l{QMessageBox::detailedText} {detailed text} property is
|
|
523 |
always interpreted as plain text. The \l{QMessageBox::text} {main
|
|
524 |
text} and \l{QMessageBox::informativeText} {informative text}
|
|
525 |
properties can be either plain text or rich text. These strings
|
|
526 |
are interpreted according to the setting of the
|
|
527 |
\l{QMessageBox::textFormat} {text format} property. The default
|
|
528 |
setting is \l{Qt::AutoText} {auto-text}.
|
|
529 |
|
|
530 |
Note that for some plain text strings containing XML
|
|
531 |
meta-characters, the auto-text \l{Qt::mightBeRichText()} {rich
|
|
532 |
text detection test} may fail causing your plain text string to be
|
|
533 |
interpreted incorrectly as rich text. In these rare cases, use
|
|
534 |
Qt::convertFromPlainText() to convert your plain text string to a
|
|
535 |
visually equivalent rich text string, or set the
|
|
536 |
\l{QMessageBox::textFormat} {text format} property explicitly with
|
|
537 |
setTextFormat().
|
|
538 |
|
|
539 |
\section2 Severity Levels and the Icon and Pixmap Properties
|
|
540 |
|
|
541 |
QMessageBox supports four predefined message severity levels, or message
|
|
542 |
types, which really only differ in the predefined icon they each show.
|
|
543 |
Specify one of the four predefined message types by setting the
|
|
544 |
\l{QMessageBox::icon}{icon} property to one of the
|
|
545 |
\l{QMessageBox::Icon}{predefined icons}. The following rules are
|
|
546 |
guidelines:
|
|
547 |
|
|
548 |
\table
|
|
549 |
\row
|
|
550 |
\o \img qmessagebox-quest.png
|
|
551 |
\o \l Question
|
|
552 |
\o For asking a question during normal operations.
|
|
553 |
\row
|
|
554 |
\o \img qmessagebox-info.png
|
|
555 |
\o \l Information
|
|
556 |
\o For reporting information about normal operations.
|
|
557 |
\row
|
|
558 |
\o \img qmessagebox-warn.png
|
|
559 |
\o \l Warning
|
|
560 |
\o For reporting non-critical errors.
|
|
561 |
\row
|
|
562 |
\o \img qmessagebox-crit.png
|
|
563 |
\o \l Critical
|
|
564 |
\o For reporting critical errors.
|
|
565 |
\endtable
|
|
566 |
|
|
567 |
\l{QMessageBox::Icon}{Predefined icons} are not defined by QMessageBox, but
|
|
568 |
provided by the style. The default value is \l{QMessageBox::NoIcon}
|
|
569 |
{No Icon}. The message boxes are otherwise the same for all cases. When
|
|
570 |
using a standard icon, use the one recommended in the table, or use the
|
|
571 |
one recommended by the style guidelines for your platform. If none of the
|
|
572 |
standard icons is right for your message box, you can use a custom icon by
|
|
573 |
setting the \l{QMessageBox::iconPixmap}{icon pixmap} property instead of
|
|
574 |
setting the \l{QMessageBox::icon}{icon} property.
|
|
575 |
|
|
576 |
In summary, to set an icon, use \e{either} setIcon() for one of the
|
|
577 |
standard icons, \e{or} setIconPixmap() for a custom icon.
|
|
578 |
|
|
579 |
\section1 The Static Functions API
|
|
580 |
|
|
581 |
Building message boxes with the static functions API, although
|
|
582 |
convenient, is less flexible than using the property-based API,
|
|
583 |
because the static function signatures lack parameters for setting
|
|
584 |
the \l{QMessageBox::informativeText} {informative text} and
|
|
585 |
\l{QMessageBox::detailedText} {detailed text} properties. One
|
|
586 |
work-around for this has been to use the \c{title} parameter as
|
|
587 |
the message box main text and the \c{text} parameter as the
|
|
588 |
message box informative text. Because this has the obvious
|
|
589 |
drawback of making a less readable message box, platform
|
|
590 |
guidelines do not recommend it. The \e{Microsoft Windows User
|
|
591 |
Interface Guidelines} recommend using the
|
|
592 |
\l{QCoreApplication::applicationName} {application name} as the
|
|
593 |
\l{QMessageBox::setWindowTitle()} {window's title}, which means
|
|
594 |
that if you have an informative text in addition to your main
|
|
595 |
text, you must concatenate it to the \c{text} parameter.
|
|
596 |
|
|
597 |
Note that the static function signatures have changed with respect
|
|
598 |
to their button parameters, which are now used to set the
|
|
599 |
\l{QMessageBox::standardButtons} {standard buttons} and the
|
|
600 |
\l{QMessageBox::defaultButton()} {default button}.
|
|
601 |
|
|
602 |
Static functions are available for creating information(),
|
|
603 |
question(), warning(), and critical() message boxes.
|
|
604 |
|
|
605 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 0
|
|
606 |
|
|
607 |
The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
|
|
608 |
how to use QMessageBox and the other built-in Qt dialogs.
|
|
609 |
|
|
610 |
\section1 Advanced Usage
|
|
611 |
|
|
612 |
If the \l{QMessageBox::StandardButtons} {standard buttons} are not
|
|
613 |
flexible enough for your message box, you can use the addButton()
|
|
614 |
overload that takes a text and a ButtonRoleto to add custom
|
|
615 |
buttons. The ButtonRole is used by QMessageBox to determine the
|
|
616 |
ordering of the buttons on screen (which varies according to the
|
|
617 |
platform). You can test the value of clickedButton() after calling
|
|
618 |
exec(). For example,
|
|
619 |
|
|
620 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 2
|
|
621 |
|
|
622 |
\section1 Default and Escape Keys
|
|
623 |
|
|
624 |
The default button (i.e., the button activated when \key Enter is
|
|
625 |
pressed) can be specified using setDefaultButton(). If a default
|
|
626 |
button is not specified, QMessageBox tries to find one based on
|
|
627 |
the \l{ButtonRole} {button roles} of the buttons used in the
|
|
628 |
message box.
|
|
629 |
|
|
630 |
The escape button (the button activated when \key Esc is pressed)
|
|
631 |
can be specified using setEscapeButton(). If an escape button is
|
|
632 |
not specified, QMessageBox tries to find one using these rules:
|
|
633 |
|
|
634 |
\list 1
|
|
635 |
|
|
636 |
\o If there is only one button, it is the button activated when
|
|
637 |
\key Esc is pressed.
|
|
638 |
|
|
639 |
\o If there is a \l Cancel button, it is the button activated when
|
|
640 |
\key Esc is pressed.
|
|
641 |
|
|
642 |
\o If there is exactly one button having either
|
|
643 |
\l{QMessageBox::RejectRole} {the Reject role} or the
|
|
644 |
\l{QMessageBox::NoRole} {the No role}, it is the button
|
|
645 |
activated when \key Esc is pressed.
|
|
646 |
|
|
647 |
\endlist
|
|
648 |
|
|
649 |
When an escape button can't be determined using these rules,
|
|
650 |
pressing \key Esc has no effect.
|
|
651 |
|
|
652 |
\sa QDialogButtonBox, {fowler}{GUI Design Handbook: Message Box}, {Standard Dialogs Example}, {Application Example}
|
|
653 |
*/
|
|
654 |
|
|
655 |
/*!
|
|
656 |
\enum QMessageBox::StandardButton
|
|
657 |
\since 4.2
|
|
658 |
|
|
659 |
These enums describe flags for standard buttons. Each button has a
|
|
660 |
defined \l ButtonRole.
|
|
661 |
|
|
662 |
\value Ok An "OK" button defined with the \l AcceptRole.
|
|
663 |
\value Open A "Open" button defined with the \l AcceptRole.
|
|
664 |
\value Save A "Save" button defined with the \l AcceptRole.
|
|
665 |
\value Cancel A "Cancel" button defined with the \l RejectRole.
|
|
666 |
\value Close A "Close" button defined with the \l RejectRole.
|
|
667 |
\value Discard A "Discard" or "Don't Save" button, depending on the platform,
|
|
668 |
defined with the \l DestructiveRole.
|
|
669 |
\value Apply An "Apply" button defined with the \l ApplyRole.
|
|
670 |
\value Reset A "Reset" button defined with the \l ResetRole.
|
|
671 |
\value RestoreDefaults A "Restore Defaults" button defined with the \l ResetRole.
|
|
672 |
\value Help A "Help" button defined with the \l HelpRole.
|
|
673 |
\value SaveAll A "Save All" button defined with the \l AcceptRole.
|
|
674 |
\value Yes A "Yes" button defined with the \l YesRole.
|
|
675 |
\value YesToAll A "Yes to All" button defined with the \l YesRole.
|
|
676 |
\value No A "No" button defined with the \l NoRole.
|
|
677 |
\value NoToAll A "No to All" button defined with the \l NoRole.
|
|
678 |
\value Abort An "Abort" button defined with the \l RejectRole.
|
|
679 |
\value Retry A "Retry" button defined with the \l AcceptRole.
|
|
680 |
\value Ignore An "Ignore" button defined with the \l AcceptRole.
|
|
681 |
|
|
682 |
\value NoButton An invalid button.
|
|
683 |
|
|
684 |
\omitvalue FirstButton
|
|
685 |
\omitvalue LastButton
|
|
686 |
|
|
687 |
The following values are obsolete:
|
|
688 |
|
|
689 |
\value YesAll Use YesToAll instead.
|
|
690 |
\value NoAll Use NoToAll instead.
|
|
691 |
\value Default Use the \c defaultButton argument of
|
|
692 |
information(), warning(), etc. instead, or call
|
|
693 |
setDefaultButton().
|
|
694 |
\value Escape Call setEscapeButton() instead.
|
|
695 |
\value FlagMask
|
|
696 |
\value ButtonMask
|
|
697 |
|
|
698 |
\sa ButtonRole, standardButtons
|
|
699 |
*/
|
|
700 |
|
|
701 |
/*!
|
|
702 |
\fn void QMessageBox::buttonClicked(QAbstractButton *button)
|
|
703 |
|
|
704 |
This signal is emitted whenever a button is clicked inside the QMessageBox.
|
|
705 |
The button that was clicked in returned in \a button.
|
|
706 |
*/
|
|
707 |
|
|
708 |
/*!
|
|
709 |
Constructs a message box with no text and no buttons. \a parent is
|
|
710 |
passed to the QDialog constructor.
|
|
711 |
|
|
712 |
On Mac OS X, if you want your message box to appear
|
|
713 |
as a Qt::Sheet of its \a parent, set the message box's
|
|
714 |
\l{setWindowModality()} {window modality} to Qt::WindowModal or use open().
|
|
715 |
Otherwise, the message box will be a standard dialog.
|
|
716 |
|
|
717 |
*/
|
|
718 |
QMessageBox::QMessageBox(QWidget *parent)
|
|
719 |
: QDialog(*new QMessageBoxPrivate, parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
|
720 |
{
|
|
721 |
Q_D(QMessageBox);
|
|
722 |
d->init();
|
|
723 |
}
|
|
724 |
|
|
725 |
/*!
|
|
726 |
Constructs a message box with the given \a icon, \a title, \a
|
|
727 |
text, and standard \a buttons. Standard or custom buttons can be
|
|
728 |
added at any time using addButton(). The \a parent and \a f
|
|
729 |
arguments are passed to the QDialog constructor.
|
|
730 |
|
|
731 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
732 |
{application modal} dialog box. If \a parent is a widget, the
|
|
733 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
734 |
parent.
|
|
735 |
|
|
736 |
On Mac OS X, if \a parent is not 0 and you want your message box
|
|
737 |
to appear as a Qt::Sheet of that parent, set the message box's
|
|
738 |
\l{setWindowModality()} {window modality} to Qt::WindowModal
|
|
739 |
(default). Otherwise, the message box will be a standard dialog.
|
|
740 |
|
|
741 |
\sa setWindowTitle(), setText(), setIcon(), setStandardButtons()
|
|
742 |
*/
|
|
743 |
QMessageBox::QMessageBox(Icon icon, const QString &title, const QString &text,
|
|
744 |
StandardButtons buttons, QWidget *parent,
|
|
745 |
Qt::WindowFlags f)
|
|
746 |
: QDialog(*new QMessageBoxPrivate, parent, f | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
|
747 |
{
|
|
748 |
Q_D(QMessageBox);
|
|
749 |
d->init(title, text);
|
|
750 |
setIcon(icon);
|
|
751 |
if (buttons != NoButton)
|
|
752 |
setStandardButtons(buttons);
|
|
753 |
}
|
|
754 |
|
|
755 |
/*!
|
|
756 |
Destroys the message box.
|
|
757 |
*/
|
|
758 |
QMessageBox::~QMessageBox()
|
|
759 |
{
|
|
760 |
}
|
|
761 |
|
|
762 |
/*!
|
|
763 |
\since 4.2
|
|
764 |
|
|
765 |
Adds the given \a button to the message box with the specified \a
|
|
766 |
role.
|
|
767 |
|
|
768 |
\sa removeButton(), button(), setStandardButtons()
|
|
769 |
*/
|
|
770 |
void QMessageBox::addButton(QAbstractButton *button, ButtonRole role)
|
|
771 |
{
|
|
772 |
Q_D(QMessageBox);
|
|
773 |
if (!button)
|
|
774 |
return;
|
|
775 |
removeButton(button);
|
|
776 |
d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);
|
|
777 |
d->customButtonList.append(button);
|
|
778 |
d->autoAddOkButton = false;
|
|
779 |
}
|
|
780 |
|
|
781 |
/*!
|
|
782 |
\since 4.2
|
|
783 |
\overload
|
|
784 |
|
|
785 |
Creates a button with the given \a text, adds it to the message box for the
|
|
786 |
specified \a role, and returns it.
|
|
787 |
*/
|
|
788 |
QPushButton *QMessageBox::addButton(const QString& text, ButtonRole role)
|
|
789 |
{
|
|
790 |
Q_D(QMessageBox);
|
|
791 |
QPushButton *pushButton = new QPushButton(text);
|
|
792 |
addButton(pushButton, role);
|
|
793 |
d->updateSize();
|
|
794 |
return pushButton;
|
|
795 |
}
|
|
796 |
|
|
797 |
/*!
|
|
798 |
\since 4.2
|
|
799 |
\overload
|
|
800 |
|
|
801 |
Adds a standard \a button to the message box if it is valid to do so, and
|
|
802 |
returns the push button.
|
|
803 |
|
|
804 |
\sa setStandardButtons()
|
|
805 |
*/
|
|
806 |
QPushButton *QMessageBox::addButton(StandardButton button)
|
|
807 |
{
|
|
808 |
Q_D(QMessageBox);
|
|
809 |
QPushButton *pushButton = d->buttonBox->addButton((QDialogButtonBox::StandardButton)button);
|
|
810 |
if (pushButton)
|
|
811 |
d->autoAddOkButton = false;
|
|
812 |
return pushButton;
|
|
813 |
}
|
|
814 |
|
|
815 |
/*!
|
|
816 |
\since 4.2
|
|
817 |
|
|
818 |
Removes \a button from the button box without deleting it.
|
|
819 |
|
|
820 |
\sa addButton(), setStandardButtons()
|
|
821 |
*/
|
|
822 |
void QMessageBox::removeButton(QAbstractButton *button)
|
|
823 |
{
|
|
824 |
Q_D(QMessageBox);
|
|
825 |
d->customButtonList.removeAll(button);
|
|
826 |
if (d->escapeButton == button)
|
|
827 |
d->escapeButton = 0;
|
|
828 |
if (d->defaultButton == button)
|
|
829 |
d->defaultButton = 0;
|
|
830 |
d->buttonBox->removeButton(button);
|
|
831 |
d->updateSize();
|
|
832 |
}
|
|
833 |
|
|
834 |
/*!
|
|
835 |
\property QMessageBox::standardButtons
|
|
836 |
\brief collection of standard buttons in the message box
|
|
837 |
\since 4.2
|
|
838 |
|
|
839 |
This property controls which standard buttons are used by the message box.
|
|
840 |
|
|
841 |
By default, this property contains no standard buttons.
|
|
842 |
|
|
843 |
\sa addButton()
|
|
844 |
*/
|
|
845 |
void QMessageBox::setStandardButtons(StandardButtons buttons)
|
|
846 |
{
|
|
847 |
Q_D(QMessageBox);
|
|
848 |
d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));
|
|
849 |
|
|
850 |
QList<QAbstractButton *> buttonList = d->buttonBox->buttons();
|
|
851 |
if (!buttonList.contains(d->escapeButton))
|
|
852 |
d->escapeButton = 0;
|
|
853 |
if (!buttonList.contains(d->defaultButton))
|
|
854 |
d->defaultButton = 0;
|
|
855 |
d->autoAddOkButton = false;
|
|
856 |
d->updateSize();
|
|
857 |
}
|
|
858 |
|
|
859 |
QMessageBox::StandardButtons QMessageBox::standardButtons() const
|
|
860 |
{
|
|
861 |
Q_D(const QMessageBox);
|
|
862 |
return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons()));
|
|
863 |
}
|
|
864 |
|
|
865 |
/*!
|
|
866 |
\since 4.2
|
|
867 |
|
|
868 |
Returns the standard button enum value corresponding to the given \a button,
|
|
869 |
or NoButton if the given \a button isn't a standard button.
|
|
870 |
|
|
871 |
\sa button(), standardButtons()
|
|
872 |
*/
|
|
873 |
QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const
|
|
874 |
{
|
|
875 |
Q_D(const QMessageBox);
|
|
876 |
return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);
|
|
877 |
}
|
|
878 |
|
|
879 |
/*!
|
|
880 |
\since 4.2
|
|
881 |
|
|
882 |
Returns a pointer corresponding to the standard button \a which,
|
|
883 |
or 0 if the standard button doesn't exist in this message box.
|
|
884 |
|
|
885 |
\sa standardButtons, standardButton()
|
|
886 |
*/
|
|
887 |
QAbstractButton *QMessageBox::button(StandardButton which) const
|
|
888 |
{
|
|
889 |
Q_D(const QMessageBox);
|
|
890 |
return d->buttonBox->button(QDialogButtonBox::StandardButton(which));
|
|
891 |
}
|
|
892 |
|
|
893 |
/*!
|
|
894 |
\since 4.2
|
|
895 |
|
|
896 |
Returns the button that is activated when escape is pressed.
|
|
897 |
|
|
898 |
By default, QMessageBox attempts to automatically detect an
|
|
899 |
escape button as follows:
|
|
900 |
|
|
901 |
\list 1
|
|
902 |
\o If there is only one button, it is made the escape button.
|
|
903 |
\o If there is a \l Cancel button, it is made the escape button.
|
|
904 |
\o On Mac OS X only, if there is exactly one button with the role
|
|
905 |
QMessageBox::RejectRole, it is made the escape button.
|
|
906 |
\endlist
|
|
907 |
|
|
908 |
When an escape button could not be automatically detected, pressing
|
|
909 |
\key Esc has no effect.
|
|
910 |
|
|
911 |
\sa addButton()
|
|
912 |
*/
|
|
913 |
QAbstractButton *QMessageBox::escapeButton() const
|
|
914 |
{
|
|
915 |
Q_D(const QMessageBox);
|
|
916 |
return d->escapeButton;
|
|
917 |
}
|
|
918 |
|
|
919 |
/*!
|
|
920 |
\since 4.2
|
|
921 |
|
|
922 |
Sets the button that gets activated when the \key Escape key is
|
|
923 |
pressed to \a button.
|
|
924 |
|
|
925 |
\sa addButton(), clickedButton()
|
|
926 |
*/
|
|
927 |
void QMessageBox::setEscapeButton(QAbstractButton *button)
|
|
928 |
{
|
|
929 |
Q_D(QMessageBox);
|
|
930 |
if (d->buttonBox->buttons().contains(button))
|
|
931 |
d->escapeButton = button;
|
|
932 |
}
|
|
933 |
|
|
934 |
/*!
|
|
935 |
\since 4.3
|
|
936 |
|
|
937 |
Sets the buttons that gets activated when the \key Escape key is
|
|
938 |
pressed to \a button.
|
|
939 |
|
|
940 |
\sa addButton(), clickedButton()
|
|
941 |
*/
|
|
942 |
void QMessageBox::setEscapeButton(QMessageBox::StandardButton button)
|
|
943 |
{
|
|
944 |
Q_D(QMessageBox);
|
|
945 |
setEscapeButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));
|
|
946 |
}
|
|
947 |
|
|
948 |
void QMessageBoxPrivate::detectEscapeButton()
|
|
949 |
{
|
|
950 |
if (escapeButton) { // escape button explicitly set
|
|
951 |
detectedEscapeButton = escapeButton;
|
|
952 |
return;
|
|
953 |
}
|
|
954 |
|
|
955 |
// Cancel button automatically becomes escape button
|
|
956 |
detectedEscapeButton = buttonBox->button(QDialogButtonBox::Cancel);
|
|
957 |
if (detectedEscapeButton)
|
|
958 |
return;
|
|
959 |
|
|
960 |
// If there is only one button, make it the escape button
|
|
961 |
const QList<QAbstractButton *> buttons = buttonBox->buttons();
|
|
962 |
if (buttons.count() == 1) {
|
|
963 |
detectedEscapeButton = buttons.first();
|
|
964 |
return;
|
|
965 |
}
|
|
966 |
|
|
967 |
// if the message box has one RejectRole button, make it the escape button
|
|
968 |
for (int i = 0; i < buttons.count(); i++) {
|
|
969 |
if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::RejectRole) {
|
|
970 |
if (detectedEscapeButton) { // already detected!
|
|
971 |
detectedEscapeButton = 0;
|
|
972 |
break;
|
|
973 |
}
|
|
974 |
detectedEscapeButton = buttons.at(i);
|
|
975 |
}
|
|
976 |
}
|
|
977 |
if (detectedEscapeButton)
|
|
978 |
return;
|
|
979 |
|
|
980 |
// if the message box has one NoRole button, make it the escape button
|
|
981 |
for (int i = 0; i < buttons.count(); i++) {
|
|
982 |
if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::NoRole) {
|
|
983 |
if (detectedEscapeButton) { // already detected!
|
|
984 |
detectedEscapeButton = 0;
|
|
985 |
break;
|
|
986 |
}
|
|
987 |
detectedEscapeButton = buttons.at(i);
|
|
988 |
}
|
|
989 |
}
|
|
990 |
}
|
|
991 |
|
|
992 |
/*!
|
|
993 |
\since 4.2
|
|
994 |
|
|
995 |
Returns the button that was clicked by the user,
|
|
996 |
or 0 if the user hit the \key Esc key and
|
|
997 |
no \l{setEscapeButton()}{escape button} was set.
|
|
998 |
|
|
999 |
If exec() hasn't been called yet, returns 0.
|
|
1000 |
|
|
1001 |
Example:
|
|
1002 |
|
|
1003 |
\snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 3
|
|
1004 |
|
|
1005 |
\sa standardButton(), button()
|
|
1006 |
*/
|
|
1007 |
QAbstractButton *QMessageBox::clickedButton() const
|
|
1008 |
{
|
|
1009 |
Q_D(const QMessageBox);
|
|
1010 |
return d->clickedButton;
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
/*!
|
|
1014 |
\since 4.2
|
|
1015 |
|
|
1016 |
Returns the button that should be the message box's
|
|
1017 |
\l{QPushButton::setDefault()}{default button}. Returns 0
|
|
1018 |
if no default button was set.
|
|
1019 |
|
|
1020 |
\sa addButton(), QPushButton::setDefault()
|
|
1021 |
*/
|
|
1022 |
QPushButton *QMessageBox::defaultButton() const
|
|
1023 |
{
|
|
1024 |
Q_D(const QMessageBox);
|
|
1025 |
return d->defaultButton;
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
/*!
|
|
1029 |
\since 4.2
|
|
1030 |
|
|
1031 |
Sets the message box's \l{QPushButton::setDefault()}{default button}
|
|
1032 |
to \a button.
|
|
1033 |
|
|
1034 |
\sa addButton(), QPushButton::setDefault()
|
|
1035 |
*/
|
|
1036 |
void QMessageBox::setDefaultButton(QPushButton *button)
|
|
1037 |
{
|
|
1038 |
Q_D(QMessageBox);
|
|
1039 |
if (!d->buttonBox->buttons().contains(button))
|
|
1040 |
return;
|
|
1041 |
d->defaultButton = button;
|
|
1042 |
button->setDefault(true);
|
|
1043 |
button->setFocus();
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
/*!
|
|
1047 |
\since 4.3
|
|
1048 |
|
|
1049 |
Sets the message box's \l{QPushButton::setDefault()}{default button}
|
|
1050 |
to \a button.
|
|
1051 |
|
|
1052 |
\sa addButton(), QPushButton::setDefault()
|
|
1053 |
*/
|
|
1054 |
void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)
|
|
1055 |
{
|
|
1056 |
Q_D(QMessageBox);
|
|
1057 |
setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
/*!
|
|
1061 |
\property QMessageBox::text
|
|
1062 |
\brief the message box text to be displayed.
|
|
1063 |
|
|
1064 |
The text will be interpreted either as a plain text or as rich text,
|
|
1065 |
depending on the text format setting (\l QMessageBox::textFormat).
|
|
1066 |
The default setting is Qt::AutoText, i.e., the message box will try
|
|
1067 |
to auto-detect the format of the text.
|
|
1068 |
|
|
1069 |
The default value of this property is an empty string.
|
|
1070 |
|
|
1071 |
\sa textFormat, QMessageBox::informativeText, QMessageBox::detailedText
|
|
1072 |
*/
|
|
1073 |
QString QMessageBox::text() const
|
|
1074 |
{
|
|
1075 |
Q_D(const QMessageBox);
|
|
1076 |
return d->label->text();
|
|
1077 |
}
|
|
1078 |
|
|
1079 |
void QMessageBox::setText(const QString &text)
|
|
1080 |
{
|
|
1081 |
Q_D(QMessageBox);
|
|
1082 |
d->label->setText(text);
|
|
1083 |
d->label->setWordWrap(d->label->textFormat() == Qt::RichText
|
|
1084 |
|| (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text)));
|
|
1085 |
d->updateSize();
|
|
1086 |
}
|
|
1087 |
|
|
1088 |
/*!
|
|
1089 |
\enum QMessageBox::Icon
|
|
1090 |
|
|
1091 |
This enum has the following values:
|
|
1092 |
|
|
1093 |
\value NoIcon the message box does not have any icon.
|
|
1094 |
|
|
1095 |
\value Question an icon indicating that
|
|
1096 |
the message is asking a question.
|
|
1097 |
|
|
1098 |
\value Information an icon indicating that
|
|
1099 |
the message is nothing out of the ordinary.
|
|
1100 |
|
|
1101 |
\value Warning an icon indicating that the
|
|
1102 |
message is a warning, but can be dealt with.
|
|
1103 |
|
|
1104 |
\value Critical an icon indicating that
|
|
1105 |
the message represents a critical problem.
|
|
1106 |
|
|
1107 |
*/
|
|
1108 |
|
|
1109 |
/*!
|
|
1110 |
\property QMessageBox::icon
|
|
1111 |
\brief the message box's icon
|
|
1112 |
|
|
1113 |
The icon of the message box can be specified with one of the
|
|
1114 |
values:
|
|
1115 |
|
|
1116 |
\list
|
|
1117 |
\o QMessageBox::NoIcon
|
|
1118 |
\o QMessageBox::Question
|
|
1119 |
\o QMessageBox::Information
|
|
1120 |
\o QMessageBox::Warning
|
|
1121 |
\o QMessageBox::Critical
|
|
1122 |
\endlist
|
|
1123 |
|
|
1124 |
The default is QMessageBox::NoIcon.
|
|
1125 |
|
|
1126 |
The pixmap used to display the actual icon depends on the current
|
|
1127 |
\l{QWidget::style()} {GUI style}. You can also set a custom pixmap
|
|
1128 |
for the icon by setting the \l{QMessageBox::iconPixmap} {icon
|
|
1129 |
pixmap} property.
|
|
1130 |
|
|
1131 |
\sa iconPixmap
|
|
1132 |
*/
|
|
1133 |
QMessageBox::Icon QMessageBox::icon() const
|
|
1134 |
{
|
|
1135 |
Q_D(const QMessageBox);
|
|
1136 |
return d->icon;
|
|
1137 |
}
|
|
1138 |
|
|
1139 |
void QMessageBox::setIcon(Icon icon)
|
|
1140 |
{
|
|
1141 |
Q_D(QMessageBox);
|
|
1142 |
setIconPixmap(QMessageBoxPrivate::standardIcon((QMessageBox::Icon)icon,
|
|
1143 |
this));
|
|
1144 |
d->icon = icon;
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
/*!
|
|
1148 |
\property QMessageBox::iconPixmap
|
|
1149 |
\brief the current icon
|
|
1150 |
|
|
1151 |
The icon currently used by the message box. Note that it's often
|
|
1152 |
hard to draw one pixmap that looks appropriate in all GUI styles;
|
|
1153 |
you may want to supply a different pixmap for each platform.
|
|
1154 |
|
|
1155 |
By default, this property is undefined.
|
|
1156 |
|
|
1157 |
\sa icon
|
|
1158 |
*/
|
|
1159 |
QPixmap QMessageBox::iconPixmap() const
|
|
1160 |
{
|
|
1161 |
Q_D(const QMessageBox);
|
|
1162 |
if (d->iconLabel && d->iconLabel->pixmap())
|
|
1163 |
return *d->iconLabel->pixmap();
|
|
1164 |
return QPixmap();
|
|
1165 |
}
|
|
1166 |
|
|
1167 |
void QMessageBox::setIconPixmap(const QPixmap &pixmap)
|
|
1168 |
{
|
|
1169 |
Q_D(QMessageBox);
|
|
1170 |
d->iconLabel->setPixmap(pixmap);
|
|
1171 |
d->updateSize();
|
|
1172 |
d->icon = NoIcon;
|
|
1173 |
}
|
|
1174 |
|
|
1175 |
/*!
|
|
1176 |
\property QMessageBox::textFormat
|
|
1177 |
\brief the format of the text displayed by the message box
|
|
1178 |
|
|
1179 |
The current text format used by the message box. See the \l
|
|
1180 |
Qt::TextFormat enum for an explanation of the possible options.
|
|
1181 |
|
|
1182 |
The default format is Qt::AutoText.
|
|
1183 |
|
|
1184 |
\sa setText()
|
|
1185 |
*/
|
|
1186 |
Qt::TextFormat QMessageBox::textFormat() const
|
|
1187 |
{
|
|
1188 |
Q_D(const QMessageBox);
|
|
1189 |
return d->label->textFormat();
|
|
1190 |
}
|
|
1191 |
|
|
1192 |
void QMessageBox::setTextFormat(Qt::TextFormat format)
|
|
1193 |
{
|
|
1194 |
Q_D(QMessageBox);
|
|
1195 |
d->label->setTextFormat(format);
|
|
1196 |
d->label->setWordWrap(format == Qt::RichText
|
|
1197 |
|| (format == Qt::AutoText && Qt::mightBeRichText(d->label->text())));
|
|
1198 |
d->updateSize();
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
/*!
|
|
1202 |
\reimp
|
|
1203 |
*/
|
|
1204 |
bool QMessageBox::event(QEvent *e)
|
|
1205 |
{
|
|
1206 |
bool result =QDialog::event(e);
|
|
1207 |
switch (e->type()) {
|
|
1208 |
case QEvent::LayoutRequest:
|
|
1209 |
d_func()->updateSize();
|
|
1210 |
break;
|
|
1211 |
case QEvent::LanguageChange:
|
|
1212 |
d_func()->retranslateStrings();
|
|
1213 |
break;
|
|
1214 |
#ifdef Q_WS_WINCE
|
|
1215 |
case QEvent::OkRequest:
|
|
1216 |
case QEvent::HelpRequest: {
|
|
1217 |
QString bName =
|
|
1218 |
(e->type() == QEvent::OkRequest)
|
|
1219 |
? QApplication::translate("QMessageBox", "OK")
|
|
1220 |
: QApplication::translate("QMessageBox", "Help");
|
|
1221 |
QList<QPushButton*> list = qFindChildren<QPushButton*>(this);
|
|
1222 |
for (int i=0; i<list.size(); ++i) {
|
|
1223 |
QPushButton *pb = list.at(i);
|
|
1224 |
if (pb->text() == bName) {
|
|
1225 |
if (pb->isEnabled())
|
|
1226 |
pb->click();
|
|
1227 |
return pb->isEnabled();
|
|
1228 |
}
|
|
1229 |
}
|
|
1230 |
}
|
|
1231 |
#endif
|
|
1232 |
default:
|
|
1233 |
break;
|
|
1234 |
}
|
|
1235 |
return result;
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
/*!
|
|
1239 |
\reimp
|
|
1240 |
*/
|
|
1241 |
void QMessageBox::resizeEvent(QResizeEvent *event)
|
|
1242 |
{
|
|
1243 |
QDialog::resizeEvent(event);
|
|
1244 |
}
|
|
1245 |
|
|
1246 |
/*!
|
|
1247 |
\reimp
|
|
1248 |
*/
|
|
1249 |
void QMessageBox::closeEvent(QCloseEvent *e)
|
|
1250 |
{
|
|
1251 |
Q_D(QMessageBox);
|
|
1252 |
if (!d->detectedEscapeButton) {
|
|
1253 |
e->ignore();
|
|
1254 |
return;
|
|
1255 |
}
|
|
1256 |
QDialog::closeEvent(e);
|
|
1257 |
d->clickedButton = d->detectedEscapeButton;
|
|
1258 |
setResult(d->execReturnCode(d->detectedEscapeButton));
|
|
1259 |
}
|
|
1260 |
|
|
1261 |
/*!
|
|
1262 |
\reimp
|
|
1263 |
*/
|
|
1264 |
void QMessageBox::changeEvent(QEvent *ev)
|
|
1265 |
{
|
|
1266 |
Q_D(QMessageBox);
|
|
1267 |
switch (ev->type()) {
|
|
1268 |
case QEvent::StyleChange:
|
|
1269 |
{
|
|
1270 |
if (d->icon != NoIcon)
|
|
1271 |
setIcon(d->icon);
|
|
1272 |
Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this));
|
|
1273 |
d->label->setTextInteractionFlags(flags);
|
|
1274 |
d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this));
|
|
1275 |
if (d->informativeLabel)
|
|
1276 |
d->informativeLabel->setTextInteractionFlags(flags);
|
|
1277 |
// intentional fall through
|
|
1278 |
}
|
|
1279 |
case QEvent::FontChange:
|
|
1280 |
case QEvent::ApplicationFontChange:
|
|
1281 |
#ifdef Q_WS_MAC
|
|
1282 |
{
|
|
1283 |
QFont f = font();
|
|
1284 |
f.setBold(true);
|
|
1285 |
d->label->setFont(f);
|
|
1286 |
}
|
|
1287 |
#endif
|
|
1288 |
default:
|
|
1289 |
break;
|
|
1290 |
}
|
|
1291 |
QDialog::changeEvent(ev);
|
|
1292 |
}
|
|
1293 |
|
|
1294 |
/*!
|
|
1295 |
\reimp
|
|
1296 |
*/
|
|
1297 |
void QMessageBox::keyPressEvent(QKeyEvent *e)
|
|
1298 |
{
|
|
1299 |
Q_D(QMessageBox);
|
|
1300 |
if (e->key() == Qt::Key_Escape
|
|
1301 |
#ifdef Q_WS_MAC
|
|
1302 |
|| (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period)
|
|
1303 |
#endif
|
|
1304 |
) {
|
|
1305 |
if (d->detectedEscapeButton) {
|
|
1306 |
#ifdef Q_WS_MAC
|
|
1307 |
d->detectedEscapeButton->animateClick();
|
|
1308 |
#else
|
|
1309 |
d->detectedEscapeButton->click();
|
|
1310 |
#endif
|
|
1311 |
}
|
|
1312 |
return;
|
|
1313 |
}
|
|
1314 |
|
|
1315 |
#if defined (Q_OS_WIN) && !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
|
|
1316 |
if (e == QKeySequence::Copy) {
|
|
1317 |
QString separator = QString::fromLatin1("---------------------------\n");
|
|
1318 |
QString textToCopy = separator;
|
|
1319 |
separator.prepend(QLatin1Char('\n'));
|
|
1320 |
textToCopy += windowTitle() + separator; // title
|
|
1321 |
textToCopy += d->label->text() + separator; // text
|
|
1322 |
|
|
1323 |
if (d->informativeLabel)
|
|
1324 |
textToCopy += d->informativeLabel->text() + separator;
|
|
1325 |
|
|
1326 |
QString buttonTexts;
|
|
1327 |
QList<QAbstractButton *> buttons = d->buttonBox->buttons();
|
|
1328 |
for (int i = 0; i < buttons.count(); i++) {
|
|
1329 |
buttonTexts += buttons[i]->text() + QLatin1String(" ");
|
|
1330 |
}
|
|
1331 |
textToCopy += buttonTexts + separator;
|
|
1332 |
|
|
1333 |
QApplication::clipboard()->setText(textToCopy);
|
|
1334 |
return;
|
|
1335 |
}
|
|
1336 |
#endif //QT_NO_SHORTCUT QT_NO_CLIPBOARD Q_OS_WIN
|
|
1337 |
|
|
1338 |
#ifndef QT_NO_SHORTCUT
|
|
1339 |
if (!(e->modifiers() & Qt::AltModifier)) {
|
|
1340 |
int key = e->key() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
|
|
1341 |
if (key) {
|
|
1342 |
const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
|
|
1343 |
for (int i = 0; i < buttons.count(); ++i) {
|
|
1344 |
QAbstractButton *pb = buttons.at(i);
|
|
1345 |
int acc = pb->shortcut() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
|
|
1346 |
if (acc == key) {
|
|
1347 |
pb->animateClick();
|
|
1348 |
return;
|
|
1349 |
}
|
|
1350 |
}
|
|
1351 |
}
|
|
1352 |
}
|
|
1353 |
#endif
|
|
1354 |
QDialog::keyPressEvent(e);
|
|
1355 |
}
|
|
1356 |
|
|
1357 |
#ifdef Q_WS_WINCE
|
|
1358 |
/*!
|
|
1359 |
\reimp
|
|
1360 |
*/
|
|
1361 |
void QMessageBox::setVisible(bool visible)
|
|
1362 |
{
|
|
1363 |
Q_D(QMessageBox);
|
|
1364 |
if (visible)
|
|
1365 |
d->hideSpecial();
|
|
1366 |
QDialog::setVisible(visible);
|
|
1367 |
}
|
|
1368 |
#endif
|
|
1369 |
|
|
1370 |
|
|
1371 |
/*!
|
|
1372 |
\overload
|
|
1373 |
|
|
1374 |
Opens the dialog and connects its finished() or buttonClicked() signal to
|
|
1375 |
the slot specified by \a receiver and \a member. If the slot in \a member
|
|
1376 |
has a pointer for its first parameter the connection is to buttonClicked(),
|
|
1377 |
otherwise the connection is to finished().
|
|
1378 |
|
|
1379 |
The signal will be disconnected from the slot when the dialog is closed.
|
|
1380 |
*/
|
|
1381 |
void QMessageBox::open(QObject *receiver, const char *member)
|
|
1382 |
{
|
|
1383 |
Q_D(QMessageBox);
|
|
1384 |
const char *signal = member && strchr(member, '*') ? SIGNAL(buttonClicked(QAbstractButton*))
|
|
1385 |
: SIGNAL(finished(int));
|
|
1386 |
connect(this, signal, receiver, member);
|
|
1387 |
d->signalToDisconnectOnClose = signal;
|
|
1388 |
d->receiverToDisconnectOnClose = receiver;
|
|
1389 |
d->memberToDisconnectOnClose = member;
|
|
1390 |
QDialog::open();
|
|
1391 |
}
|
|
1392 |
|
|
1393 |
/*!
|
|
1394 |
\since 4.5
|
|
1395 |
|
|
1396 |
Returns a list of all the buttons that have been added to the message box.
|
|
1397 |
|
|
1398 |
\sa buttonRole(), addButton(), removeButton()
|
|
1399 |
*/
|
|
1400 |
QList<QAbstractButton *> QMessageBox::buttons() const
|
|
1401 |
{
|
|
1402 |
Q_D(const QMessageBox);
|
|
1403 |
return d->buttonBox->buttons();
|
|
1404 |
}
|
|
1405 |
|
|
1406 |
/*!
|
|
1407 |
\since 4.5
|
|
1408 |
|
|
1409 |
Returns the button role for the specified \a button. This function returns
|
|
1410 |
\l InvalidRole if \a button is 0 or has not been added to the message box.
|
|
1411 |
|
|
1412 |
\sa buttons(), addButton()
|
|
1413 |
*/
|
|
1414 |
QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const
|
|
1415 |
{
|
|
1416 |
Q_D(const QMessageBox);
|
|
1417 |
return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button));
|
|
1418 |
}
|
|
1419 |
|
|
1420 |
/*!
|
|
1421 |
\reimp
|
|
1422 |
*/
|
|
1423 |
void QMessageBox::showEvent(QShowEvent *e)
|
|
1424 |
{
|
|
1425 |
Q_D(QMessageBox);
|
|
1426 |
if (d->autoAddOkButton) {
|
|
1427 |
addButton(Ok);
|
|
1428 |
#if defined(Q_WS_WINCE)
|
|
1429 |
d->hideSpecial();
|
|
1430 |
#endif
|
|
1431 |
}
|
|
1432 |
if (d->detailsButton)
|
|
1433 |
addButton(d->detailsButton, QMessageBox::ActionRole);
|
|
1434 |
d->detectEscapeButton();
|
|
1435 |
d->updateSize();
|
|
1436 |
|
|
1437 |
#ifndef QT_NO_ACCESSIBILITY
|
|
1438 |
QAccessible::updateAccessibility(this, 0, QAccessible::Alert);
|
|
1439 |
#endif
|
|
1440 |
#ifdef Q_WS_WIN
|
|
1441 |
HMENU systemMenu = GetSystemMenu((HWND)winId(), FALSE);
|
|
1442 |
if (!d->detectedEscapeButton) {
|
|
1443 |
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
|
|
1444 |
}
|
|
1445 |
else {
|
|
1446 |
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
|
|
1447 |
}
|
|
1448 |
#endif
|
|
1449 |
QDialog::showEvent(e);
|
|
1450 |
}
|
|
1451 |
|
|
1452 |
|
|
1453 |
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,
|
|
1454 |
QMessageBox::Icon icon,
|
|
1455 |
const QString& title, const QString& text,
|
|
1456 |
QMessageBox::StandardButtons buttons,
|
|
1457 |
QMessageBox::StandardButton defaultButton)
|
|
1458 |
{
|
|
1459 |
// necessary for source compatibility with Qt 4.0 and 4.1
|
|
1460 |
// handles (Yes, No) and (Yes|Default, No)
|
|
1461 |
if (defaultButton && !(buttons & defaultButton))
|
|
1462 |
return (QMessageBox::StandardButton)
|
|
1463 |
QMessageBoxPrivate::showOldMessageBox(parent, icon, title,
|
|
1464 |
text, int(buttons),
|
|
1465 |
int(defaultButton), 0);
|
|
1466 |
|
|
1467 |
QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent);
|
|
1468 |
QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&msgBox);
|
|
1469 |
Q_ASSERT(buttonBox != 0);
|
|
1470 |
|
|
1471 |
uint mask = QMessageBox::FirstButton;
|
|
1472 |
while (mask <= QMessageBox::LastButton) {
|
|
1473 |
uint sb = buttons & mask;
|
|
1474 |
mask <<= 1;
|
|
1475 |
if (!sb)
|
|
1476 |
continue;
|
|
1477 |
QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb);
|
|
1478 |
// Choose the first accept role as the default
|
|
1479 |
if (msgBox.defaultButton())
|
|
1480 |
continue;
|
|
1481 |
if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
|
1482 |
|| (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton)))
|
|
1483 |
msgBox.setDefaultButton(button);
|
|
1484 |
}
|
|
1485 |
if (msgBox.exec() == -1)
|
|
1486 |
return QMessageBox::Cancel;
|
|
1487 |
return msgBox.standardButton(msgBox.clickedButton());
|
|
1488 |
}
|
|
1489 |
|
|
1490 |
/*!
|
|
1491 |
\since 4.2
|
|
1492 |
|
|
1493 |
Opens an information message box with the specified \a title and
|
|
1494 |
\a text. The standard \a buttons are added to the message box. \a
|
|
1495 |
defaultButton specifies the button used when \key Enter is
|
|
1496 |
pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
|
1497 |
If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
|
1498 |
chooses a suitable default automatically.
|
|
1499 |
|
|
1500 |
Returns the identity of the standard button that was clicked. If
|
|
1501 |
\key Esc was pressed instead, the \l{Default and Escape Keys}
|
|
1502 |
{escape button} is returned.
|
|
1503 |
|
|
1504 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1505 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1506 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1507 |
parent.
|
|
1508 |
|
|
1509 |
\sa question(), warning(), critical()
|
|
1510 |
*/
|
|
1511 |
QMessageBox::StandardButton QMessageBox::information(QWidget *parent, const QString &title,
|
|
1512 |
const QString& text, StandardButtons buttons,
|
|
1513 |
StandardButton defaultButton)
|
|
1514 |
{
|
|
1515 |
return showNewMessageBox(parent, Information, title, text, buttons,
|
|
1516 |
defaultButton);
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
|
|
1520 |
/*!
|
|
1521 |
\since 4.2
|
|
1522 |
|
|
1523 |
Opens a question message box with the specified \a title and \a
|
|
1524 |
text. The standard \a buttons are added to the message box. \a
|
|
1525 |
defaultButton specifies the button used when \key Enter is
|
|
1526 |
pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
|
1527 |
If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
|
1528 |
chooses a suitable default automatically.
|
|
1529 |
|
|
1530 |
Returns the identity of the standard button that was clicked. If
|
|
1531 |
\key Esc was pressed instead, the \l{Default and Escape Keys}
|
|
1532 |
{escape button} is returned.
|
|
1533 |
|
|
1534 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1535 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1536 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1537 |
parent.
|
|
1538 |
|
|
1539 |
\sa information(), warning(), critical()
|
|
1540 |
*/
|
|
1541 |
QMessageBox::StandardButton QMessageBox::question(QWidget *parent, const QString &title,
|
|
1542 |
const QString& text, StandardButtons buttons,
|
|
1543 |
StandardButton defaultButton)
|
|
1544 |
{
|
|
1545 |
return showNewMessageBox(parent, Question, title, text, buttons, defaultButton);
|
|
1546 |
}
|
|
1547 |
|
|
1548 |
/*!
|
|
1549 |
\since 4.2
|
|
1550 |
|
|
1551 |
Opens a warning message box with the specified \a title and \a
|
|
1552 |
text. The standard \a buttons are added to the message box. \a
|
|
1553 |
defaultButton specifies the button used when \key Enter is
|
|
1554 |
pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
|
1555 |
If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
|
1556 |
chooses a suitable default automatically.
|
|
1557 |
|
|
1558 |
Returns the identity of the standard button that was clicked. If
|
|
1559 |
\key Esc was pressed instead, the \l{Default and Escape Keys}
|
|
1560 |
{escape button} is returned.
|
|
1561 |
|
|
1562 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1563 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1564 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1565 |
parent.
|
|
1566 |
|
|
1567 |
\sa question(), information(), critical()
|
|
1568 |
*/
|
|
1569 |
QMessageBox::StandardButton QMessageBox::warning(QWidget *parent, const QString &title,
|
|
1570 |
const QString& text, StandardButtons buttons,
|
|
1571 |
StandardButton defaultButton)
|
|
1572 |
{
|
|
1573 |
return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton);
|
|
1574 |
}
|
|
1575 |
|
|
1576 |
/*!
|
|
1577 |
\since 4.2
|
|
1578 |
|
|
1579 |
Opens a critical message box with the specified \a title and \a
|
|
1580 |
text. The standard \a buttons are added to the message box. \a
|
|
1581 |
defaultButton specifies the button used when \key Enter is
|
|
1582 |
pressed. \a defaultButton must refer to a button that was given in \a buttons.
|
|
1583 |
If \a defaultButton is QMessageBox::NoButton, QMessageBox
|
|
1584 |
chooses a suitable default automatically.
|
|
1585 |
|
|
1586 |
Returns the identity of the standard button that was clicked. If
|
|
1587 |
\key Esc was pressed instead, the \l{Default and Escape Keys}
|
|
1588 |
{escape button} is returned.
|
|
1589 |
|
|
1590 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1591 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1592 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1593 |
parent.
|
|
1594 |
|
|
1595 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
1596 |
If you want to do this, you should create the dialog
|
|
1597 |
yourself using one of the QMessageBox constructors.
|
|
1598 |
|
|
1599 |
\sa question(), warning(), information()
|
|
1600 |
*/
|
|
1601 |
QMessageBox::StandardButton QMessageBox::critical(QWidget *parent, const QString &title,
|
|
1602 |
const QString& text, StandardButtons buttons,
|
|
1603 |
StandardButton defaultButton)
|
|
1604 |
{
|
|
1605 |
return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton);
|
|
1606 |
}
|
|
1607 |
|
|
1608 |
/*!
|
|
1609 |
Displays a simple about box with title \a title and text \a
|
|
1610 |
text. The about box's parent is \a parent.
|
|
1611 |
|
|
1612 |
about() looks for a suitable icon in four locations:
|
|
1613 |
|
|
1614 |
\list 1
|
|
1615 |
\o It prefers \link QWidget::windowIcon() parent->icon() \endlink
|
|
1616 |
if that exists.
|
|
1617 |
\o If not, it tries the top-level widget containing \a parent.
|
|
1618 |
\o If that fails, it tries the \link
|
|
1619 |
QApplication::activeWindow() active window. \endlink
|
|
1620 |
\o As a last resort it uses the Information icon.
|
|
1621 |
\endlist
|
|
1622 |
|
|
1623 |
The about box has a single button labelled "OK". On Mac OS X, the
|
|
1624 |
about box is popped up as a modeless window; on other platforms,
|
|
1625 |
it is currently a window modal.
|
|
1626 |
|
|
1627 |
\sa QWidget::windowIcon(), QApplication::activeWindow()
|
|
1628 |
*/
|
|
1629 |
void QMessageBox::about(QWidget *parent, const QString &title, const QString &text)
|
|
1630 |
{
|
|
1631 |
#ifdef Q_WS_MAC
|
|
1632 |
static QPointer<QMessageBox> oldMsgBox;
|
|
1633 |
|
|
1634 |
if (oldMsgBox && oldMsgBox->text() == text) {
|
|
1635 |
oldMsgBox->show();
|
|
1636 |
oldMsgBox->raise();
|
|
1637 |
oldMsgBox->activateWindow();
|
|
1638 |
return;
|
|
1639 |
}
|
|
1640 |
#endif
|
|
1641 |
|
|
1642 |
QMessageBox *msgBox = new QMessageBox(title, text, Information, 0, 0, 0, parent
|
|
1643 |
#ifdef Q_WS_MAC
|
|
1644 |
, Qt::WindowTitleHint | Qt::WindowSystemMenuHint
|
|
1645 |
#endif
|
|
1646 |
);
|
|
1647 |
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
1648 |
QIcon icon = msgBox->windowIcon();
|
|
1649 |
QSize size = icon.actualSize(QSize(64, 64));
|
|
1650 |
msgBox->setIconPixmap(icon.pixmap(size));
|
|
1651 |
|
|
1652 |
// should perhaps be a style hint
|
|
1653 |
#ifdef Q_WS_MAC
|
|
1654 |
oldMsgBox = msgBox;
|
|
1655 |
#if 0
|
|
1656 |
// ### doesn't work until close button is enabled in title bar
|
|
1657 |
msgBox->d_func()->autoAddOkButton = false;
|
|
1658 |
#else
|
|
1659 |
msgBox->d_func()->buttonBox->setCenterButtons(true);
|
|
1660 |
#endif
|
|
1661 |
msgBox->show();
|
|
1662 |
#else
|
|
1663 |
msgBox->exec();
|
|
1664 |
#endif
|
|
1665 |
}
|
|
1666 |
|
|
1667 |
/*!
|
|
1668 |
Displays a simple message box about Qt, with the given \a title
|
|
1669 |
and centered over \a parent (if \a parent is not 0). The message
|
|
1670 |
includes the version number of Qt being used by the application.
|
|
1671 |
|
|
1672 |
This is useful for inclusion in the \gui Help menu of an application,
|
|
1673 |
as shown in the \l{mainwindows/menus}{Menus} example.
|
|
1674 |
|
|
1675 |
QApplication provides this functionality as a slot.
|
|
1676 |
|
|
1677 |
On Mac OS X, the about box is popped up as a modeless window; on
|
|
1678 |
other platforms, it is currently window modal.
|
|
1679 |
|
|
1680 |
\sa QApplication::aboutQt()
|
|
1681 |
*/
|
|
1682 |
void QMessageBox::aboutQt(QWidget *parent, const QString &title)
|
|
1683 |
{
|
|
1684 |
#ifdef Q_WS_MAC
|
|
1685 |
static QPointer<QMessageBox> oldMsgBox;
|
|
1686 |
|
|
1687 |
if (oldMsgBox) {
|
|
1688 |
oldMsgBox->show();
|
|
1689 |
oldMsgBox->raise();
|
|
1690 |
oldMsgBox->activateWindow();
|
|
1691 |
return;
|
|
1692 |
}
|
|
1693 |
#endif
|
|
1694 |
|
|
1695 |
QString translatedTextAboutQtCaption;
|
|
1696 |
translatedTextAboutQtCaption = QMessageBox::tr(
|
|
1697 |
"<h3>About Qt</h3>"
|
|
1698 |
"<p>This program uses Qt version %1.</p>"
|
|
1699 |
).arg(QLatin1String(QT_VERSION_STR));
|
|
1700 |
QString translatedTextAboutQtText;
|
|
1701 |
translatedTextAboutQtText = QMessageBox::tr(
|
|
1702 |
"<p>Qt is a C++ toolkit for cross-platform application "
|
|
1703 |
"development.</p>"
|
|
1704 |
"<p>Qt provides single-source portability across MS Windows, "
|
|
1705 |
"Mac OS X, Linux, and all major commercial Unix variants. "
|
|
1706 |
"Qt is also available for embedded devices as Qt for Embedded Linux "
|
|
1707 |
"and Qt for Windows CE.</p>"
|
|
1708 |
"<p>Qt is available under three different licensing options designed "
|
|
1709 |
"to accommodate the needs of our various users.</p>"
|
|
1710 |
"<p>Qt licensed under our commercial license agreement is appropriate "
|
|
1711 |
"for development of proprietary/commercial software where you do not "
|
|
1712 |
"want to share any source code with third parties or otherwise cannot "
|
|
1713 |
"comply with the terms of the GNU LGPL version 2.1 or GNU GPL version "
|
|
1714 |
"3.0.</p>"
|
|
1715 |
"<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
|
|
1716 |
"development of Qt applications (proprietary or open source) provided "
|
|
1717 |
"you can comply with the terms and conditions of the GNU LGPL version "
|
|
1718 |
"2.1.</p>"
|
|
1719 |
"<p>Qt licensed under the GNU General Public License version 3.0 is "
|
|
1720 |
"appropriate for the development of Qt applications where you wish to "
|
|
1721 |
"use such applications in combination with software subject to the "
|
|
1722 |
"terms of the GNU GPL version 3.0 or where you are otherwise willing "
|
|
1723 |
"to comply with the terms of the GNU GPL version 3.0.</p>"
|
|
1724 |
"<p>Please see <a href=\"http://qt.nokia.com/products/licensing\">qt.nokia.com/products/licensing</a> "
|
|
1725 |
"for an overview of Qt licensing.</p>"
|
|
1726 |
"<p>Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).</p>"
|
|
1727 |
"<p>Qt is a Nokia product. See <a href=\"http://qt.nokia.com/\">qt.nokia.com</a> "
|
|
1728 |
"for more information.</p>"
|
|
1729 |
);
|
|
1730 |
QMessageBox *msgBox = new QMessageBox(parent);
|
|
1731 |
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
1732 |
msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title);
|
|
1733 |
msgBox->setText(translatedTextAboutQtCaption);
|
|
1734 |
msgBox->setInformativeText(translatedTextAboutQtText);
|
|
1735 |
|
|
1736 |
QPixmap pm(QLatin1String(":/trolltech/qmessagebox/images/qtlogo-64.png"));
|
|
1737 |
if (!pm.isNull())
|
|
1738 |
msgBox->setIconPixmap(pm);
|
|
1739 |
#if defined(Q_WS_WINCE)
|
|
1740 |
msgBox->setDefaultButton(msgBox->addButton(QMessageBox::Ok));
|
|
1741 |
#endif
|
|
1742 |
|
|
1743 |
// should perhaps be a style hint
|
|
1744 |
#ifdef Q_WS_MAC
|
|
1745 |
oldMsgBox = msgBox;
|
|
1746 |
#if 0
|
|
1747 |
// ### doesn't work until close button is enabled in title bar
|
|
1748 |
msgBox->d_func()->autoAddOkButton = false;
|
|
1749 |
#else
|
|
1750 |
msgBox->d_func()->buttonBox->setCenterButtons(true);
|
|
1751 |
#endif
|
|
1752 |
msgBox->show();
|
|
1753 |
#else
|
|
1754 |
msgBox->exec();
|
|
1755 |
#endif
|
|
1756 |
}
|
|
1757 |
|
|
1758 |
/*!
|
|
1759 |
\internal
|
|
1760 |
*/
|
|
1761 |
QSize QMessageBox::sizeHint() const
|
|
1762 |
{
|
|
1763 |
// ### Qt 5: remove
|
|
1764 |
return QDialog::sizeHint();
|
|
1765 |
}
|
|
1766 |
|
|
1767 |
/////////////////////////////////////////////////////////////////////////////////////////
|
|
1768 |
// Source and binary compatibility routines for 4.0 and 4.1
|
|
1769 |
|
|
1770 |
static QMessageBox::StandardButton newButton(int button)
|
|
1771 |
{
|
|
1772 |
// this is needed for source compatibility with Qt 4.0 and 4.1
|
|
1773 |
if (button == QMessageBox::NoButton || (button & NewButtonMask))
|
|
1774 |
return QMessageBox::StandardButton(button & QMessageBox::ButtonMask);
|
|
1775 |
|
|
1776 |
#if QT_VERSION < 0x050000
|
|
1777 |
// this is needed for binary compatibility with Qt 4.0 and 4.1
|
|
1778 |
switch (button & Old_ButtonMask) {
|
|
1779 |
case Old_Ok:
|
|
1780 |
return QMessageBox::Ok;
|
|
1781 |
case Old_Cancel:
|
|
1782 |
return QMessageBox::Cancel;
|
|
1783 |
case Old_Yes:
|
|
1784 |
return QMessageBox::Yes;
|
|
1785 |
case Old_No:
|
|
1786 |
return QMessageBox::No;
|
|
1787 |
case Old_Abort:
|
|
1788 |
return QMessageBox::Abort;
|
|
1789 |
case Old_Retry:
|
|
1790 |
return QMessageBox::Retry;
|
|
1791 |
case Old_Ignore:
|
|
1792 |
return QMessageBox::Ignore;
|
|
1793 |
case Old_YesAll:
|
|
1794 |
return QMessageBox::YesToAll;
|
|
1795 |
case Old_NoAll:
|
|
1796 |
return QMessageBox::NoToAll;
|
|
1797 |
default:
|
|
1798 |
return QMessageBox::NoButton;
|
|
1799 |
}
|
|
1800 |
#endif
|
|
1801 |
}
|
|
1802 |
|
|
1803 |
static bool detectedCompat(int button0, int button1, int button2)
|
|
1804 |
{
|
|
1805 |
if (button0 != 0 && !(button0 & NewButtonMask))
|
|
1806 |
return true;
|
|
1807 |
if (button1 != 0 && !(button1 & NewButtonMask))
|
|
1808 |
return true;
|
|
1809 |
if (button2 != 0 && !(button2 & NewButtonMask))
|
|
1810 |
return true;
|
|
1811 |
return false;
|
|
1812 |
}
|
|
1813 |
|
|
1814 |
QAbstractButton *QMessageBoxPrivate::findButton(int button0, int button1, int button2, int flags)
|
|
1815 |
{
|
|
1816 |
Q_Q(QMessageBox);
|
|
1817 |
int button = 0;
|
|
1818 |
|
|
1819 |
if (button0 & flags) {
|
|
1820 |
button = button0;
|
|
1821 |
} else if (button1 & flags) {
|
|
1822 |
button = button1;
|
|
1823 |
} else if (button2 & flags) {
|
|
1824 |
button = button2;
|
|
1825 |
}
|
|
1826 |
return q->button(newButton(button));
|
|
1827 |
}
|
|
1828 |
|
|
1829 |
void QMessageBoxPrivate::addOldButtons(int button0, int button1, int button2)
|
|
1830 |
{
|
|
1831 |
Q_Q(QMessageBox);
|
|
1832 |
q->addButton(newButton(button0));
|
|
1833 |
q->addButton(newButton(button1));
|
|
1834 |
q->addButton(newButton(button2));
|
|
1835 |
q->setDefaultButton(
|
|
1836 |
static_cast<QPushButton *>(findButton(button0, button1, button2, QMessageBox::Default)));
|
|
1837 |
q->setEscapeButton(findButton(button0, button1, button2, QMessageBox::Escape));
|
|
1838 |
compatMode = detectedCompat(button0, button1, button2);
|
|
1839 |
}
|
|
1840 |
|
|
1841 |
QAbstractButton *QMessageBoxPrivate::abstractButtonForId(int id) const
|
|
1842 |
{
|
|
1843 |
Q_Q(const QMessageBox);
|
|
1844 |
QAbstractButton *result = customButtonList.value(id);
|
|
1845 |
if (result)
|
|
1846 |
return result;
|
|
1847 |
if (id & QMessageBox::FlagMask) // for compatibility with Qt 4.0/4.1 (even if it is silly)
|
|
1848 |
return 0;
|
|
1849 |
return q->button(newButton(id));
|
|
1850 |
}
|
|
1851 |
|
|
1852 |
int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
|
1853 |
const QString &title, const QString &text,
|
|
1854 |
int button0, int button1, int button2)
|
|
1855 |
{
|
|
1856 |
QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);
|
|
1857 |
messageBox.d_func()->addOldButtons(button0, button1, button2);
|
|
1858 |
return messageBox.exec();
|
|
1859 |
}
|
|
1860 |
|
|
1861 |
int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
|
|
1862 |
const QString &title, const QString &text,
|
|
1863 |
const QString &button0Text,
|
|
1864 |
const QString &button1Text,
|
|
1865 |
const QString &button2Text,
|
|
1866 |
int defaultButtonNumber,
|
|
1867 |
int escapeButtonNumber)
|
|
1868 |
{
|
|
1869 |
QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);
|
|
1870 |
QString myButton0Text = button0Text;
|
|
1871 |
if (myButton0Text.isEmpty())
|
|
1872 |
myButton0Text = QDialogButtonBox::tr("OK");
|
|
1873 |
messageBox.addButton(myButton0Text, QMessageBox::ActionRole);
|
|
1874 |
if (!button1Text.isEmpty())
|
|
1875 |
messageBox.addButton(button1Text, QMessageBox::ActionRole);
|
|
1876 |
if (!button2Text.isEmpty())
|
|
1877 |
messageBox.addButton(button2Text, QMessageBox::ActionRole);
|
|
1878 |
|
|
1879 |
const QList<QAbstractButton *> &buttonList = messageBox.d_func()->customButtonList;
|
|
1880 |
messageBox.setDefaultButton(static_cast<QPushButton *>(buttonList.value(defaultButtonNumber)));
|
|
1881 |
messageBox.setEscapeButton(buttonList.value(escapeButtonNumber));
|
|
1882 |
|
|
1883 |
return messageBox.exec();
|
|
1884 |
}
|
|
1885 |
|
|
1886 |
void QMessageBoxPrivate::retranslateStrings()
|
|
1887 |
{
|
|
1888 |
#ifndef QT_NO_TEXTEDIT
|
|
1889 |
if (detailsButton)
|
|
1890 |
detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
|
|
1891 |
#endif
|
|
1892 |
}
|
|
1893 |
|
|
1894 |
/*!
|
|
1895 |
\obsolete
|
|
1896 |
|
|
1897 |
Constructs a message box with a \a title, a \a text, an \a icon,
|
|
1898 |
and up to three buttons.
|
|
1899 |
|
|
1900 |
The \a icon must be one of the following:
|
|
1901 |
\list
|
|
1902 |
\o QMessageBox::NoIcon
|
|
1903 |
\o QMessageBox::Question
|
|
1904 |
\o QMessageBox::Information
|
|
1905 |
\o QMessageBox::Warning
|
|
1906 |
\o QMessageBox::Critical
|
|
1907 |
\endlist
|
|
1908 |
|
|
1909 |
Each button, \a button0, \a button1 and \a button2, can have one
|
|
1910 |
of the following values:
|
|
1911 |
\list
|
|
1912 |
\o QMessageBox::NoButton
|
|
1913 |
\o QMessageBox::Ok
|
|
1914 |
\o QMessageBox::Cancel
|
|
1915 |
\o QMessageBox::Yes
|
|
1916 |
\o QMessageBox::No
|
|
1917 |
\o QMessageBox::Abort
|
|
1918 |
\o QMessageBox::Retry
|
|
1919 |
\o QMessageBox::Ignore
|
|
1920 |
\o QMessageBox::YesAll
|
|
1921 |
\o QMessageBox::NoAll
|
|
1922 |
\endlist
|
|
1923 |
|
|
1924 |
Use QMessageBox::NoButton for the later parameters to have fewer
|
|
1925 |
than three buttons in your message box. If you don't specify any
|
|
1926 |
buttons at all, QMessageBox will provide an Ok button.
|
|
1927 |
|
|
1928 |
One of the buttons can be OR-ed with the QMessageBox::Default
|
|
1929 |
flag to make it the default button (clicked when Enter is
|
|
1930 |
pressed).
|
|
1931 |
|
|
1932 |
One of the buttons can be OR-ed with the QMessageBox::Escape flag
|
|
1933 |
to make it the cancel or close button (clicked when \key Esc is
|
|
1934 |
pressed).
|
|
1935 |
|
|
1936 |
\snippet doc/src/snippets/dialogs/dialogs.cpp 2
|
|
1937 |
|
|
1938 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1939 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1940 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1941 |
parent.
|
|
1942 |
|
|
1943 |
The \a parent and \a f arguments are passed to
|
|
1944 |
the QDialog constructor.
|
|
1945 |
|
|
1946 |
\sa setWindowTitle(), setText(), setIcon()
|
|
1947 |
*/
|
|
1948 |
QMessageBox::QMessageBox(const QString &title, const QString &text, Icon icon,
|
|
1949 |
int button0, int button1, int button2, QWidget *parent,
|
|
1950 |
Qt::WindowFlags f)
|
|
1951 |
: QDialog(*new QMessageBoxPrivate, parent,
|
|
1952 |
f /*| Qt::MSWindowsFixedSizeDialogHint #### */| Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
|
1953 |
{
|
|
1954 |
Q_D(QMessageBox);
|
|
1955 |
d->init(title, text);
|
|
1956 |
setIcon(icon);
|
|
1957 |
d->addOldButtons(button0, button1, button2);
|
|
1958 |
}
|
|
1959 |
|
|
1960 |
/*!
|
|
1961 |
\obsolete
|
|
1962 |
|
|
1963 |
Opens an information message box with the given \a title and the
|
|
1964 |
\a text. The dialog may have up to three buttons. Each of the
|
|
1965 |
buttons, \a button0, \a button1 and \a button2 may be set to one
|
|
1966 |
of the following values:
|
|
1967 |
|
|
1968 |
\list
|
|
1969 |
\o QMessageBox::NoButton
|
|
1970 |
\o QMessageBox::Ok
|
|
1971 |
\o QMessageBox::Cancel
|
|
1972 |
\o QMessageBox::Yes
|
|
1973 |
\o QMessageBox::No
|
|
1974 |
\o QMessageBox::Abort
|
|
1975 |
\o QMessageBox::Retry
|
|
1976 |
\o QMessageBox::Ignore
|
|
1977 |
\o QMessageBox::YesAll
|
|
1978 |
\o QMessageBox::NoAll
|
|
1979 |
\endlist
|
|
1980 |
|
|
1981 |
If you don't want all three buttons, set the last button, or last
|
|
1982 |
two buttons to QMessageBox::NoButton.
|
|
1983 |
|
|
1984 |
One button can be OR-ed with QMessageBox::Default, and one
|
|
1985 |
button can be OR-ed with QMessageBox::Escape.
|
|
1986 |
|
|
1987 |
Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
|
1988 |
of the button that was clicked.
|
|
1989 |
|
|
1990 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
1991 |
{application modal} dialog box. If \a parent is a widget, the
|
|
1992 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
1993 |
parent.
|
|
1994 |
|
|
1995 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
1996 |
If you want to do this, you should create the dialog
|
|
1997 |
yourself using one of the QMessageBox constructors.
|
|
1998 |
|
|
1999 |
\sa question(), warning(), critical()
|
|
2000 |
*/
|
|
2001 |
int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,
|
|
2002 |
int button0, int button1, int button2)
|
|
2003 |
{
|
|
2004 |
return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
|
|
2005 |
button0, button1, button2);
|
|
2006 |
}
|
|
2007 |
|
|
2008 |
/*!
|
|
2009 |
\obsolete
|
|
2010 |
\overload
|
|
2011 |
|
|
2012 |
Displays an information message box with the given \a title and
|
|
2013 |
\a text, as well as one, two or three buttons. Returns the index
|
|
2014 |
of the button that was clicked (0, 1 or 2).
|
|
2015 |
|
|
2016 |
\a button0Text is the text of the first button, and is optional.
|
|
2017 |
If \a button0Text is not supplied, "OK" (translated) will be
|
|
2018 |
used. \a button1Text is the text of the second button, and is
|
|
2019 |
optional. \a button2Text is the text of the third button, and is
|
|
2020 |
optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
|
2021 |
default button; pressing Return or Enter is the same as clicking
|
|
2022 |
the default button. It defaults to 0 (the first button). \a
|
|
2023 |
escapeButtonNumber is the index of the escape button; pressing
|
|
2024 |
\key Esc is the same as clicking this button. It defaults to -1;
|
|
2025 |
supply 0, 1 or 2 to make pressing \key Esc equivalent to clicking
|
|
2026 |
the relevant button.
|
|
2027 |
|
|
2028 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2029 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2030 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2031 |
parent.
|
|
2032 |
|
|
2033 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2034 |
If you want to do this, you should create the dialog
|
|
2035 |
yourself using one of the QMessageBox constructors.
|
|
2036 |
|
|
2037 |
\sa question(), warning(), critical()
|
|
2038 |
*/
|
|
2039 |
|
|
2040 |
int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,
|
|
2041 |
const QString& button0Text, const QString& button1Text,
|
|
2042 |
const QString& button2Text, int defaultButtonNumber,
|
|
2043 |
int escapeButtonNumber)
|
|
2044 |
{
|
|
2045 |
return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
|
|
2046 |
button0Text, button1Text, button2Text,
|
|
2047 |
defaultButtonNumber, escapeButtonNumber);
|
|
2048 |
}
|
|
2049 |
|
|
2050 |
/*!
|
|
2051 |
\obsolete
|
|
2052 |
|
|
2053 |
Opens a question message box with the given \a title and \a text.
|
|
2054 |
The dialog may have up to three buttons. Each of the buttons, \a
|
|
2055 |
button0, \a button1 and \a button2 may be set to one of the
|
|
2056 |
following values:
|
|
2057 |
|
|
2058 |
\list
|
|
2059 |
\o QMessageBox::NoButton
|
|
2060 |
\o QMessageBox::Ok
|
|
2061 |
\o QMessageBox::Cancel
|
|
2062 |
\o QMessageBox::Yes
|
|
2063 |
\o QMessageBox::No
|
|
2064 |
\o QMessageBox::Abort
|
|
2065 |
\o QMessageBox::Retry
|
|
2066 |
\o QMessageBox::Ignore
|
|
2067 |
\o QMessageBox::YesAll
|
|
2068 |
\o QMessageBox::NoAll
|
|
2069 |
\endlist
|
|
2070 |
|
|
2071 |
If you don't want all three buttons, set the last button, or last
|
|
2072 |
two buttons to QMessageBox::NoButton.
|
|
2073 |
|
|
2074 |
One button can be OR-ed with QMessageBox::Default, and one
|
|
2075 |
button can be OR-ed with QMessageBox::Escape.
|
|
2076 |
|
|
2077 |
Returns the identity (QMessageBox::Yes, or QMessageBox::No, etc.)
|
|
2078 |
of the button that was clicked.
|
|
2079 |
|
|
2080 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2081 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2082 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2083 |
parent.
|
|
2084 |
|
|
2085 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2086 |
If you want to do this, you should create the dialog
|
|
2087 |
yourself using one of the QMessageBox constructors.
|
|
2088 |
|
|
2089 |
\sa information(), warning(), critical()
|
|
2090 |
*/
|
|
2091 |
int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,
|
|
2092 |
int button0, int button1, int button2)
|
|
2093 |
{
|
|
2094 |
return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
|
|
2095 |
button0, button1, button2);
|
|
2096 |
}
|
|
2097 |
|
|
2098 |
/*!
|
|
2099 |
\obsolete
|
|
2100 |
\overload
|
|
2101 |
|
|
2102 |
Displays a question message box with the given \a title and \a
|
|
2103 |
text, as well as one, two or three buttons. Returns the index of
|
|
2104 |
the button that was clicked (0, 1 or 2).
|
|
2105 |
|
|
2106 |
\a button0Text is the text of the first button, and is optional.
|
|
2107 |
If \a button0Text is not supplied, "OK" (translated) will be used.
|
|
2108 |
\a button1Text is the text of the second button, and is optional.
|
|
2109 |
\a button2Text is the text of the third button, and is optional.
|
|
2110 |
\a defaultButtonNumber (0, 1 or 2) is the index of the default
|
|
2111 |
button; pressing Return or Enter is the same as clicking the
|
|
2112 |
default button. It defaults to 0 (the first button). \a
|
|
2113 |
escapeButtonNumber is the index of the Escape button; pressing
|
|
2114 |
Escape is the same as clicking this button. It defaults to -1;
|
|
2115 |
supply 0, 1 or 2 to make pressing Escape equivalent to clicking
|
|
2116 |
the relevant button.
|
|
2117 |
|
|
2118 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2119 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2120 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2121 |
parent.
|
|
2122 |
|
|
2123 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2124 |
If you want to do this, you should create the dialog
|
|
2125 |
yourself using one of the QMessageBox constructors.
|
|
2126 |
|
|
2127 |
\sa information(), warning(), critical()
|
|
2128 |
*/
|
|
2129 |
int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,
|
|
2130 |
const QString& button0Text, const QString& button1Text,
|
|
2131 |
const QString& button2Text, int defaultButtonNumber,
|
|
2132 |
int escapeButtonNumber)
|
|
2133 |
{
|
|
2134 |
return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
|
|
2135 |
button0Text, button1Text, button2Text,
|
|
2136 |
defaultButtonNumber, escapeButtonNumber);
|
|
2137 |
}
|
|
2138 |
|
|
2139 |
|
|
2140 |
/*!
|
|
2141 |
\obsolete
|
|
2142 |
|
|
2143 |
Opens a warning message box with the given \a title and \a text.
|
|
2144 |
The dialog may have up to three buttons. Each of the button
|
|
2145 |
parameters, \a button0, \a button1 and \a button2 may be set to
|
|
2146 |
one of the following values:
|
|
2147 |
|
|
2148 |
\list
|
|
2149 |
\o QMessageBox::NoButton
|
|
2150 |
\o QMessageBox::Ok
|
|
2151 |
\o QMessageBox::Cancel
|
|
2152 |
\o QMessageBox::Yes
|
|
2153 |
\o QMessageBox::No
|
|
2154 |
\o QMessageBox::Abort
|
|
2155 |
\o QMessageBox::Retry
|
|
2156 |
\o QMessageBox::Ignore
|
|
2157 |
\o QMessageBox::YesAll
|
|
2158 |
\o QMessageBox::NoAll
|
|
2159 |
\endlist
|
|
2160 |
|
|
2161 |
If you don't want all three buttons, set the last button, or last
|
|
2162 |
two buttons to QMessageBox::NoButton.
|
|
2163 |
|
|
2164 |
One button can be OR-ed with QMessageBox::Default, and one
|
|
2165 |
button can be OR-ed with QMessageBox::Escape.
|
|
2166 |
|
|
2167 |
Returns the identity (QMessageBox::Ok or QMessageBox::No or ...)
|
|
2168 |
of the button that was clicked.
|
|
2169 |
|
|
2170 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2171 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2172 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2173 |
parent.
|
|
2174 |
|
|
2175 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2176 |
If you want to do this, you should create the dialog
|
|
2177 |
yourself using one of the QMessageBox constructors.
|
|
2178 |
|
|
2179 |
\sa information(), question(), critical()
|
|
2180 |
*/
|
|
2181 |
int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,
|
|
2182 |
int button0, int button1, int button2)
|
|
2183 |
{
|
|
2184 |
return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
|
|
2185 |
button0, button1, button2);
|
|
2186 |
}
|
|
2187 |
|
|
2188 |
/*!
|
|
2189 |
\obsolete
|
|
2190 |
\overload
|
|
2191 |
|
|
2192 |
Displays a warning message box with the given \a title and \a
|
|
2193 |
text, as well as one, two, or three buttons. Returns the number
|
|
2194 |
of the button that was clicked (0, 1, or 2).
|
|
2195 |
|
|
2196 |
\a button0Text is the text of the first button, and is optional.
|
|
2197 |
If \a button0Text is not supplied, "OK" (translated) will be used.
|
|
2198 |
\a button1Text is the text of the second button, and is optional,
|
|
2199 |
and \a button2Text is the text of the third button, and is
|
|
2200 |
optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
|
2201 |
default button; pressing Return or Enter is the same as clicking
|
|
2202 |
the default button. It defaults to 0 (the first button). \a
|
|
2203 |
escapeButtonNumber is the index of the Escape button; pressing
|
|
2204 |
Escape is the same as clicking this button. It defaults to -1;
|
|
2205 |
supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
|
2206 |
the relevant button.
|
|
2207 |
|
|
2208 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2209 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2210 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2211 |
parent.
|
|
2212 |
|
|
2213 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2214 |
If you want to do this, you should create the dialog
|
|
2215 |
yourself using one of the QMessageBox constructors.
|
|
2216 |
|
|
2217 |
\sa information(), question(), critical()
|
|
2218 |
*/
|
|
2219 |
int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,
|
|
2220 |
const QString& button0Text, const QString& button1Text,
|
|
2221 |
const QString& button2Text, int defaultButtonNumber,
|
|
2222 |
int escapeButtonNumber)
|
|
2223 |
{
|
|
2224 |
return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
|
|
2225 |
button0Text, button1Text, button2Text,
|
|
2226 |
defaultButtonNumber, escapeButtonNumber);
|
|
2227 |
}
|
|
2228 |
|
|
2229 |
/*!
|
|
2230 |
\obsolete
|
|
2231 |
|
|
2232 |
Opens a critical message box with the given \a title and \a text.
|
|
2233 |
The dialog may have up to three buttons. Each of the button
|
|
2234 |
parameters, \a button0, \a button1 and \a button2 may be set to
|
|
2235 |
one of the following values:
|
|
2236 |
|
|
2237 |
\list
|
|
2238 |
\o QMessageBox::NoButton
|
|
2239 |
\o QMessageBox::Ok
|
|
2240 |
\o QMessageBox::Cancel
|
|
2241 |
\o QMessageBox::Yes
|
|
2242 |
\o QMessageBox::No
|
|
2243 |
\o QMessageBox::Abort
|
|
2244 |
\o QMessageBox::Retry
|
|
2245 |
\o QMessageBox::Ignore
|
|
2246 |
\o QMessageBox::YesAll
|
|
2247 |
\o QMessageBox::NoAll
|
|
2248 |
\endlist
|
|
2249 |
|
|
2250 |
If you don't want all three buttons, set the last button, or last
|
|
2251 |
two buttons to QMessageBox::NoButton.
|
|
2252 |
|
|
2253 |
One button can be OR-ed with QMessageBox::Default, and one
|
|
2254 |
button can be OR-ed with QMessageBox::Escape.
|
|
2255 |
|
|
2256 |
Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
|
2257 |
of the button that was clicked.
|
|
2258 |
|
|
2259 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2260 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2261 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2262 |
parent.
|
|
2263 |
|
|
2264 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2265 |
If you want to do this, you should create the dialog
|
|
2266 |
yourself using one of the QMessageBox constructors.
|
|
2267 |
|
|
2268 |
\sa information(), question(), warning()
|
|
2269 |
*/
|
|
2270 |
|
|
2271 |
int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,
|
|
2272 |
int button0, int button1, int button2)
|
|
2273 |
{
|
|
2274 |
return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
|
|
2275 |
button0, button1, button2);
|
|
2276 |
}
|
|
2277 |
|
|
2278 |
/*!
|
|
2279 |
\obsolete
|
|
2280 |
\overload
|
|
2281 |
|
|
2282 |
Displays a critical error message box with the given \a title and
|
|
2283 |
\a text, as well as one, two, or three buttons. Returns the
|
|
2284 |
number of the button that was clicked (0, 1 or 2).
|
|
2285 |
|
|
2286 |
\a button0Text is the text of the first button, and is optional.
|
|
2287 |
If \a button0Text is not supplied, "OK" (translated) will be used.
|
|
2288 |
\a button1Text is the text of the second button, and is optional,
|
|
2289 |
and \a button2Text is the text of the third button, and is
|
|
2290 |
optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
|
2291 |
default button; pressing Return or Enter is the same as clicking
|
|
2292 |
the default button. It defaults to 0 (the first button). \a
|
|
2293 |
escapeButtonNumber is the index of the Escape button; pressing
|
|
2294 |
Escape is the same as clicking this button. It defaults to -1;
|
|
2295 |
supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
|
2296 |
the relevant button.
|
|
2297 |
|
|
2298 |
If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
|
|
2299 |
{application modal} dialog box. If \a parent is a widget, the
|
|
2300 |
message box is \l{Qt::WindowModal} {window modal} relative to \a
|
|
2301 |
parent.
|
|
2302 |
|
|
2303 |
\warning Do not delete \a parent during the execution of the dialog.
|
|
2304 |
If you want to do this, you should create the dialog
|
|
2305 |
yourself using one of the QMessageBox constructors.
|
|
2306 |
|
|
2307 |
\sa information(), question(), warning()
|
|
2308 |
*/
|
|
2309 |
int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,
|
|
2310 |
const QString& button0Text, const QString& button1Text,
|
|
2311 |
const QString& button2Text, int defaultButtonNumber,
|
|
2312 |
int escapeButtonNumber)
|
|
2313 |
{
|
|
2314 |
return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
|
|
2315 |
button0Text, button1Text, button2Text,
|
|
2316 |
defaultButtonNumber, escapeButtonNumber);
|
|
2317 |
}
|
|
2318 |
|
|
2319 |
|
|
2320 |
/*!
|
|
2321 |
\obsolete
|
|
2322 |
|
|
2323 |
Returns the text of the message box button \a button, or
|
|
2324 |
an empty string if the message box does not contain the button.
|
|
2325 |
|
|
2326 |
Use button() and QPushButton::text() instead.
|
|
2327 |
*/
|
|
2328 |
QString QMessageBox::buttonText(int button) const
|
|
2329 |
{
|
|
2330 |
Q_D(const QMessageBox);
|
|
2331 |
|
|
2332 |
if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
|
|
2333 |
return abstractButton->text();
|
|
2334 |
} else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
|
|
2335 |
// for compatibility with Qt 4.0/4.1
|
|
2336 |
return QDialogButtonBox::tr("OK");
|
|
2337 |
}
|
|
2338 |
return QString();
|
|
2339 |
}
|
|
2340 |
|
|
2341 |
/*!
|
|
2342 |
\obsolete
|
|
2343 |
|
|
2344 |
Sets the text of the message box button \a button to \a text.
|
|
2345 |
Setting the text of a button that is not in the message box is
|
|
2346 |
silently ignored.
|
|
2347 |
|
|
2348 |
Use addButton() instead.
|
|
2349 |
*/
|
|
2350 |
void QMessageBox::setButtonText(int button, const QString &text)
|
|
2351 |
{
|
|
2352 |
Q_D(QMessageBox);
|
|
2353 |
if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
|
|
2354 |
abstractButton->setText(text);
|
|
2355 |
} else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
|
|
2356 |
// for compatibility with Qt 4.0/4.1
|
|
2357 |
addButton(QMessageBox::Ok)->setText(text);
|
|
2358 |
}
|
|
2359 |
}
|
|
2360 |
|
|
2361 |
#ifndef QT_NO_TEXTEDIT
|
|
2362 |
/*!
|
|
2363 |
\property QMessageBox::detailedText
|
|
2364 |
\brief the text to be displayed in the details area.
|
|
2365 |
\since 4.2
|
|
2366 |
|
|
2367 |
The text will be interpreted as a plain text.
|
|
2368 |
|
|
2369 |
By default, this property contains an empty string.
|
|
2370 |
|
|
2371 |
\sa QMessageBox::text, QMessageBox::informativeText
|
|
2372 |
*/
|
|
2373 |
QString QMessageBox::detailedText() const
|
|
2374 |
{
|
|
2375 |
Q_D(const QMessageBox);
|
|
2376 |
return d->detailsText ? d->detailsText->text() : QString();
|
|
2377 |
}
|
|
2378 |
|
|
2379 |
void QMessageBox::setDetailedText(const QString &text)
|
|
2380 |
{
|
|
2381 |
Q_D(QMessageBox);
|
|
2382 |
if (text.isEmpty()) {
|
|
2383 |
delete d->detailsText;
|
|
2384 |
d->detailsText = 0;
|
|
2385 |
removeButton(d->detailsButton);
|
|
2386 |
delete d->detailsButton;
|
|
2387 |
d->detailsButton = 0;
|
|
2388 |
return;
|
|
2389 |
}
|
|
2390 |
|
|
2391 |
if (!d->detailsText) {
|
|
2392 |
d->detailsText = new QMessageBoxDetailsText(this);
|
|
2393 |
QGridLayout* grid = qobject_cast<QGridLayout*>(layout());
|
|
2394 |
if (grid)
|
|
2395 |
grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount());
|
|
2396 |
d->detailsText->hide();
|
|
2397 |
}
|
|
2398 |
if (!d->detailsButton) {
|
|
2399 |
d->detailsButton = new QPushButton(d->detailsText->label(ShowLabel), this);
|
|
2400 |
QPushButton hideDetails(d->detailsText->label(HideLabel));
|
|
2401 |
d->detailsButton->setFixedSize(d->detailsButton->sizeHint().expandedTo(hideDetails.sizeHint()));
|
|
2402 |
}
|
|
2403 |
d->detailsText->setText(text);
|
|
2404 |
}
|
|
2405 |
#endif // QT_NO_TEXTEDIT
|
|
2406 |
|
|
2407 |
/*!
|
|
2408 |
\property QMessageBox::informativeText
|
|
2409 |
|
|
2410 |
\brief the informative text that provides a fuller description for
|
|
2411 |
the message
|
|
2412 |
|
|
2413 |
\since 4.2
|
|
2414 |
|
|
2415 |
Infromative text can be used to expand upon the text() to give more
|
|
2416 |
information to the user. On the Mac, this text appears in small
|
|
2417 |
system font below the text(). On other platforms, it is simply
|
|
2418 |
appended to the existing text.
|
|
2419 |
|
|
2420 |
By default, this property contains an empty string.
|
|
2421 |
|
|
2422 |
\sa QMessageBox::text, QMessageBox::detailedText
|
|
2423 |
*/
|
|
2424 |
QString QMessageBox::informativeText() const
|
|
2425 |
{
|
|
2426 |
Q_D(const QMessageBox);
|
|
2427 |
return d->informativeLabel ? d->informativeLabel->text() : QString();
|
|
2428 |
}
|
|
2429 |
|
|
2430 |
void QMessageBox::setInformativeText(const QString &text)
|
|
2431 |
{
|
|
2432 |
Q_D(QMessageBox);
|
|
2433 |
if (text.isEmpty()) {
|
|
2434 |
layout()->removeWidget(d->informativeLabel);
|
|
2435 |
delete d->informativeLabel;
|
|
2436 |
d->informativeLabel = 0;
|
|
2437 |
#ifndef Q_WS_MAC
|
|
2438 |
d->label->setContentsMargins(2, 0, 0, 0);
|
|
2439 |
#endif
|
|
2440 |
d->updateSize();
|
|
2441 |
return;
|
|
2442 |
}
|
|
2443 |
|
|
2444 |
if (!d->informativeLabel) {
|
|
2445 |
QLabel *label = new QLabel;
|
|
2446 |
label->setObjectName(QLatin1String("qt_msgbox_informativelabel"));
|
|
2447 |
label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this)));
|
|
2448 |
label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
2449 |
label->setOpenExternalLinks(true);
|
|
2450 |
label->setWordWrap(true);
|
|
2451 |
#ifndef Q_WS_MAC
|
|
2452 |
d->label->setContentsMargins(2, 0, 0, 0);
|
|
2453 |
label->setContentsMargins(2, 0, 0, 6);
|
|
2454 |
label->setIndent(9);
|
|
2455 |
#else
|
|
2456 |
label->setContentsMargins(16, 0, 0, 0);
|
|
2457 |
// apply a smaller font the information label on the mac
|
|
2458 |
label->setFont(qt_app_fonts_hash()->value("QTipLabel"));
|
|
2459 |
#endif
|
|
2460 |
label->setWordWrap(true);
|
|
2461 |
QGridLayout *grid = static_cast<QGridLayout *>(layout());
|
|
2462 |
grid->addWidget(label, 1, 1, 1, 1);
|
|
2463 |
d->informativeLabel = label;
|
|
2464 |
}
|
|
2465 |
d->informativeLabel->setText(text);
|
|
2466 |
d->updateSize();
|
|
2467 |
}
|
|
2468 |
|
|
2469 |
/*!
|
|
2470 |
\since 4.2
|
|
2471 |
|
|
2472 |
This function shadows QWidget::setWindowTitle().
|
|
2473 |
|
|
2474 |
Sets the title of the message box to \a title. On Mac OS X,
|
|
2475 |
the window title is ignored (as required by the Mac OS X
|
|
2476 |
Guidelines).
|
|
2477 |
*/
|
|
2478 |
void QMessageBox::setWindowTitle(const QString &title)
|
|
2479 |
{
|
|
2480 |
// Message boxes on the mac do not have a title
|
|
2481 |
#ifndef Q_WS_MAC
|
|
2482 |
QDialog::setWindowTitle(title);
|
|
2483 |
#else
|
|
2484 |
Q_UNUSED(title);
|
|
2485 |
#endif
|
|
2486 |
}
|
|
2487 |
|
|
2488 |
|
|
2489 |
/*!
|
|
2490 |
\since 4.2
|
|
2491 |
|
|
2492 |
This function shadows QWidget::setWindowModality().
|
|
2493 |
|
|
2494 |
Sets the modality of the message box to \a windowModality.
|
|
2495 |
|
|
2496 |
On Mac OS X, if the modality is set to Qt::WindowModal and the message box
|
|
2497 |
has a parent, then the message box will be a Qt::Sheet, otherwise the
|
|
2498 |
message box will be a standard dialog.
|
|
2499 |
*/
|
|
2500 |
void QMessageBox::setWindowModality(Qt::WindowModality windowModality)
|
|
2501 |
{
|
|
2502 |
QDialog::setWindowModality(windowModality);
|
|
2503 |
|
|
2504 |
if (parentWidget() && windowModality == Qt::WindowModal)
|
|
2505 |
setParent(parentWidget(), Qt::Sheet);
|
|
2506 |
else
|
|
2507 |
setParent(parentWidget(), Qt::Dialog);
|
|
2508 |
setDefaultButton(d_func()->defaultButton);
|
|
2509 |
}
|
|
2510 |
|
|
2511 |
#ifdef QT3_SUPPORT
|
|
2512 |
/*!
|
|
2513 |
\compat
|
|
2514 |
|
|
2515 |
Constructs a message box with the given \a parent, \a name, and
|
|
2516 |
window flags, \a f.
|
|
2517 |
The window title is specified by \a title, and the message box
|
|
2518 |
displays message text and an icon specified by \a text and \a icon.
|
|
2519 |
|
|
2520 |
The buttons that the user can access to respond to the message are
|
|
2521 |
defined by \a button0, \a button1, and \a button2.
|
|
2522 |
*/
|
|
2523 |
QMessageBox::QMessageBox(const QString& title,
|
|
2524 |
const QString &text, Icon icon,
|
|
2525 |
int button0, int button1, int button2,
|
|
2526 |
QWidget *parent, const char *name,
|
|
2527 |
bool modal, Qt::WindowFlags f)
|
|
2528 |
: QDialog(*new QMessageBoxPrivate, parent,
|
|
2529 |
f | Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WindowCloseButtonHint)
|
|
2530 |
{
|
|
2531 |
Q_D(QMessageBox);
|
|
2532 |
setObjectName(QString::fromAscii(name));
|
|
2533 |
d->init(title, text);
|
|
2534 |
d->addOldButtons(button0, button1, button2);
|
|
2535 |
setModal(modal);
|
|
2536 |
setIcon(icon);
|
|
2537 |
}
|
|
2538 |
|
|
2539 |
/*!
|
|
2540 |
\compat
|
|
2541 |
Constructs a message box with the given \a parent and \a name.
|
|
2542 |
*/
|
|
2543 |
QMessageBox::QMessageBox(QWidget *parent, const char *name)
|
|
2544 |
: QDialog(*new QMessageBoxPrivate, parent,
|
|
2545 |
Qt::WStyle_Customize | Qt::WStyle_DialogBorder | Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WindowCloseButtonHint)
|
|
2546 |
{
|
|
2547 |
Q_D(QMessageBox);
|
|
2548 |
setObjectName(QString::fromAscii(name));
|
|
2549 |
d->init();
|
|
2550 |
}
|
|
2551 |
|
|
2552 |
/*!
|
|
2553 |
Returns the pixmap used for a standard icon. This
|
|
2554 |
allows the pixmaps to be used in more complex message boxes.
|
|
2555 |
\a icon specifies the required icon, e.g. QMessageBox::Information,
|
|
2556 |
QMessageBox::Warning or QMessageBox::Critical.
|
|
2557 |
|
|
2558 |
\a style is unused.
|
|
2559 |
*/
|
|
2560 |
|
|
2561 |
QPixmap QMessageBox::standardIcon(Icon icon, Qt::GUIStyle style)
|
|
2562 |
{
|
|
2563 |
Q_UNUSED(style);
|
|
2564 |
return QMessageBox::standardIcon(icon);
|
|
2565 |
}
|
|
2566 |
|
|
2567 |
/*!
|
|
2568 |
\fn int QMessageBox::message(const QString &title, const QString &text,
|
|
2569 |
const QString &buttonText, QWidget *parent = 0,
|
|
2570 |
const char *name = 0)
|
|
2571 |
|
|
2572 |
Opens a modal message box with the given \a title and showing the
|
|
2573 |
given \a text. The message box has a single button which has the
|
|
2574 |
given \a buttonText (or tr("OK")). The message box is centred over
|
|
2575 |
its \a parent and is called \a name.
|
|
2576 |
|
|
2577 |
Use information(), warning(), question(), or critical() instead.
|
|
2578 |
|
|
2579 |
\oldcode
|
|
2580 |
QMessageBox::message(tr("My App"), tr("All occurrences replaced."),
|
|
2581 |
tr("Close"), this);
|
|
2582 |
\newcode
|
|
2583 |
QMessageBox::information(this, tr("My App"),
|
|
2584 |
tr("All occurrences replaced."),
|
|
2585 |
QMessageBox::Close);
|
|
2586 |
\endcode
|
|
2587 |
*/
|
|
2588 |
|
|
2589 |
/*!
|
|
2590 |
\fn bool QMessageBox::query(const QString &caption,
|
|
2591 |
const QString& text,
|
|
2592 |
const QString& yesButtonText,
|
|
2593 |
const QString& noButtonText,
|
|
2594 |
QWidget *parent, const char *name)
|
|
2595 |
|
|
2596 |
\obsolete
|
|
2597 |
|
|
2598 |
Queries the user using a modal message box with up to two buttons.
|
|
2599 |
The message box has the given \a caption (although some window
|
|
2600 |
managers don't show it), and shows the given \a text. The left
|
|
2601 |
button has the \a yesButtonText (or tr("OK")), and the right button
|
|
2602 |
has the \a noButtonText (or isn't shown). The message box is centred
|
|
2603 |
over its \a parent and is called \a name.
|
|
2604 |
|
|
2605 |
Use information(), question(), warning(), or critical() instead.
|
|
2606 |
*/
|
|
2607 |
|
|
2608 |
#endif
|
|
2609 |
|
|
2610 |
QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
|
|
2611 |
{
|
|
2612 |
QStyle *style = mb ? mb->style() : QApplication::style();
|
|
2613 |
int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb);
|
|
2614 |
QIcon tmpIcon;
|
|
2615 |
switch (icon) {
|
|
2616 |
case QMessageBox::Information:
|
|
2617 |
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb);
|
|
2618 |
break;
|
|
2619 |
case QMessageBox::Warning:
|
|
2620 |
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb);
|
|
2621 |
break;
|
|
2622 |
case QMessageBox::Critical:
|
|
2623 |
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb);
|
|
2624 |
break;
|
|
2625 |
case QMessageBox::Question:
|
|
2626 |
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb);
|
|
2627 |
default:
|
|
2628 |
break;
|
|
2629 |
}
|
|
2630 |
if (!tmpIcon.isNull())
|
|
2631 |
return tmpIcon.pixmap(iconSize, iconSize);
|
|
2632 |
return QPixmap();
|
|
2633 |
}
|
|
2634 |
|
|
2635 |
/*!
|
|
2636 |
\obsolete
|
|
2637 |
|
|
2638 |
Returns the pixmap used for a standard icon. This allows the
|
|
2639 |
pixmaps to be used in more complex message boxes. \a icon
|
|
2640 |
specifies the required icon, e.g. QMessageBox::Question,
|
|
2641 |
QMessageBox::Information, QMessageBox::Warning or
|
|
2642 |
QMessageBox::Critical.
|
|
2643 |
|
|
2644 |
Call QStyle::standardIcon() with QStyle::SP_MessageBoxInformation etc.
|
|
2645 |
instead.
|
|
2646 |
*/
|
|
2647 |
|
|
2648 |
QPixmap QMessageBox::standardIcon(Icon icon)
|
|
2649 |
{
|
|
2650 |
return QMessageBoxPrivate::standardIcon(icon, 0);
|
|
2651 |
}
|
|
2652 |
|
|
2653 |
/*!
|
|
2654 |
\typedef QMessageBox::Button
|
|
2655 |
\obsolete
|
|
2656 |
|
|
2657 |
Use QMessageBox::StandardButton instead.
|
|
2658 |
*/
|
|
2659 |
|
|
2660 |
/*!
|
|
2661 |
\fn int QMessageBox::information(QWidget *parent, const QString &title,
|
|
2662 |
const QString& text, StandardButton button0,
|
|
2663 |
StandardButton button1)
|
|
2664 |
\fn int QMessageBox::warning(QWidget *parent, const QString &title,
|
|
2665 |
const QString& text, StandardButton button0,
|
|
2666 |
StandardButton button1)
|
|
2667 |
\fn int QMessageBox::critical(QWidget *parent, const QString &title,
|
|
2668 |
const QString& text, StandardButton button0,
|
|
2669 |
StandardButton button1)
|
|
2670 |
\fn int QMessageBox::question(QWidget *parent, const QString &title,
|
|
2671 |
const QString& text, StandardButton button0,
|
|
2672 |
StandardButton button1)
|
|
2673 |
\internal
|
|
2674 |
|
|
2675 |
### Needed for Qt 4 source compatibility
|
|
2676 |
*/
|
|
2677 |
|
|
2678 |
/*!
|
|
2679 |
\fn int QMessageBox::exec()
|
|
2680 |
|
|
2681 |
Shows the message box as a \l{QDialog#Modal Dialogs}{modal dialog},
|
|
2682 |
blocking until the user closes it.
|
|
2683 |
|
|
2684 |
When using a QMessageBox with standard buttons, this functions returns a
|
|
2685 |
\l StandardButton value indicating the standard button that was clicked.
|
|
2686 |
When using QMessageBox with custom buttons, this function returns an
|
|
2687 |
opaque value; use clickedButton() to determine which button was clicked.
|
|
2688 |
|
|
2689 |
Users cannot interact with any other window in the same
|
|
2690 |
application until they close the dialog, either by clicking a
|
|
2691 |
button or by using a mechanism provided by the window system.
|
|
2692 |
|
|
2693 |
\sa show(), result()
|
|
2694 |
*/
|
|
2695 |
|
|
2696 |
QT_END_NAMESPACE
|
|
2697 |
|
|
2698 |
#include "moc_qmessagebox.cpp"
|
|
2699 |
|
|
2700 |
#endif // QT_NO_MESSAGEBOX
|