Qt 4.8
qmessagebox.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QMESSAGEBOX_H
43 #define QMESSAGEBOX_H
44 
45 #include <QtGui/qdialog.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_MESSAGEBOX
54 
55 class QLabel;
56 class QMessageBoxPrivate;
57 class QAbstractButton;
58 
60 {
61  Q_OBJECT
62  Q_ENUMS(Icon)
63  Q_FLAGS(StandardButtons)
65  // ### Qt 5: Rename 'icon' 'standardIcon' and 'iconPixmap' 'icon' (and use QIcon?)
66  Icon icon;
67  QPixmap iconPixmap;
68  Qt::TextFormat textFormat;
69  StandardButtons standardButtons;
70 #ifndef QT_NO_TEXTEDIT
72 #endif
74 
75 public:
76  enum Icon {
77  NoIcon = 0,
78  Information = 1,
79  Warning = 2,
80  Critical = 3,
81  Question = 4
82  };
83 
84  enum ButtonRole {
85  // keep this in sync with QDialogButtonBox::ButtonRole
86  InvalidRole = -1,
96 
97  NRoles
98  };
99 
101  // keep this in sync with QDialogButtonBox::StandardButton
102  NoButton = 0x00000000,
103  Ok = 0x00000400,
104  Save = 0x00000800,
105  SaveAll = 0x00001000,
106  Open = 0x00002000,
107  Yes = 0x00004000,
108  YesToAll = 0x00008000,
109  No = 0x00010000,
110  NoToAll = 0x00020000,
111  Abort = 0x00040000,
112  Retry = 0x00080000,
113  Ignore = 0x00100000,
114  Close = 0x00200000,
115  Cancel = 0x00400000,
116  Discard = 0x00800000,
117  Help = 0x01000000,
118  Apply = 0x02000000,
119  Reset = 0x04000000,
120  RestoreDefaults = 0x08000000,
121 
122  FirstButton = Ok, // internal
123  LastButton = RestoreDefaults, // internal
124 
125  YesAll = YesToAll, // obsolete
126  NoAll = NoToAll, // obsolete
127 
128  Default = 0x00000100, // obsolete
129  Escape = 0x00000200, // obsolete
130  FlagMask = 0x00000300, // obsolete
131  ButtonMask = ~FlagMask // obsolete
132  };
133  typedef StandardButton Button; // obsolete
134 
135  Q_DECLARE_FLAGS(StandardButtons, StandardButton)
136 
137  explicit QMessageBox(QWidget *parent = 0);
138  QMessageBox(Icon icon, const QString &title, const QString &text,
139  StandardButtons buttons = NoButton, QWidget *parent = 0,
140  Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
141  ~QMessageBox();
142 
143  void addButton(QAbstractButton *button, ButtonRole role);
144  QPushButton *addButton(const QString &text, ButtonRole role);
145  QPushButton *addButton(StandardButton button);
146  void removeButton(QAbstractButton *button);
147 
148 #ifdef Q_WS_WINCE
149  void setVisible(bool visible);
150 #endif
151 
152 #ifdef Q_NO_USING_KEYWORD
153 #ifndef Q_QDOC
154  void open() { QDialog::open(); }
155 #endif
156 #else
157  using QDialog::open;
158 #endif
159  void open(QObject *receiver, const char *member);
160 
162  ButtonRole buttonRole(QAbstractButton *button) const;
163 
164  void setStandardButtons(StandardButtons buttons);
165  StandardButtons standardButtons() const;
166  StandardButton standardButton(QAbstractButton *button) const;
167  QAbstractButton *button(StandardButton which) const;
168 
169  QPushButton *defaultButton() const;
170  void setDefaultButton(QPushButton *button);
171  void setDefaultButton(StandardButton button);
172 
173  QAbstractButton *escapeButton() const;
174  void setEscapeButton(QAbstractButton *button);
175  void setEscapeButton(StandardButton button);
176 
177  QAbstractButton *clickedButton() const;
178 
179  QString text() const;
180  void setText(const QString &text);
181 
182  Icon icon() const;
183  void setIcon(Icon);
184 
185  QPixmap iconPixmap() const;
186  void setIconPixmap(const QPixmap &pixmap);
187 
188  Qt::TextFormat textFormat() const;
189  void setTextFormat(Qt::TextFormat format);
190 
191  static StandardButton information(QWidget *parent, const QString &title,
192  const QString &text, StandardButtons buttons = Ok,
193  StandardButton defaultButton = NoButton);
194  // ### Qt 5: Replace Ok with Yes|No in question() function.
195  // Also consider if Ok == Yes and Cancel == No.
196  static StandardButton question(QWidget *parent, const QString &title,
197  const QString &text, StandardButtons buttons = Ok,
198  StandardButton defaultButton = NoButton);
199  static StandardButton warning(QWidget *parent, const QString &title,
200  const QString &text, StandardButtons buttons = Ok,
201  StandardButton defaultButton = NoButton);
202  static StandardButton critical(QWidget *parent, const QString &title,
203  const QString &text, StandardButtons buttons = Ok,
204  StandardButton defaultButton = NoButton);
205  static void about(QWidget *parent, const QString &title, const QString &text);
206  static void aboutQt(QWidget *parent, const QString &title = QString());
207 
208  QSize sizeHint() const;
209 
210  // the following functions are obsolete:
211 
212  QMessageBox(const QString &title, const QString &text, Icon icon,
213  int button0, int button1, int button2,
214  QWidget *parent = 0,
215  Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
216 
217  static int information(QWidget *parent, const QString &title,
218  const QString& text,
219  int button0, int button1 = 0, int button2 = 0);
220  static int information(QWidget *parent, const QString &title,
221  const QString& text,
222  const QString& button0Text,
223  const QString& button1Text = QString(),
224  const QString& button2Text = QString(),
225  int defaultButtonNumber = 0,
226  int escapeButtonNumber = -1);
227  inline static StandardButton information(QWidget *parent, const QString &title,
228  const QString& text,
229  StandardButton button0, StandardButton button1 = NoButton)
230  { return information(parent, title, text, StandardButtons(button0), button1); }
231 
232  static int question(QWidget *parent, const QString &title,
233  const QString& text,
234  int button0, int button1 = 0, int button2 = 0);
235  static int question(QWidget *parent, const QString &title,
236  const QString& text,
237  const QString& button0Text,
238  const QString& button1Text = QString(),
239  const QString& button2Text = QString(),
240  int defaultButtonNumber = 0,
241  int escapeButtonNumber = -1);
242  inline static int question(QWidget *parent, const QString &title,
243  const QString& text,
244  StandardButton button0, StandardButton button1)
245  { return question(parent, title, text, StandardButtons(button0), button1); }
246 
247  static int warning(QWidget *parent, const QString &title,
248  const QString& text,
249  int button0, int button1, int button2 = 0);
250  static int warning(QWidget *parent, const QString &title,
251  const QString& text,
252  const QString& button0Text,
253  const QString& button1Text = QString(),
254  const QString& button2Text = QString(),
255  int defaultButtonNumber = 0,
256  int escapeButtonNumber = -1);
257  inline static int warning(QWidget *parent, const QString &title,
258  const QString& text,
259  StandardButton button0, StandardButton button1)
260  { return warning(parent, title, text, StandardButtons(button0), button1); }
261 
262  static int critical(QWidget *parent, const QString &title,
263  const QString& text,
264  int button0, int button1, int button2 = 0);
265  static int critical(QWidget *parent, const QString &title,
266  const QString& text,
267  const QString& button0Text,
268  const QString& button1Text = QString(),
269  const QString& button2Text = QString(),
270  int defaultButtonNumber = 0,
271  int escapeButtonNumber = -1);
272  inline static int critical(QWidget *parent, const QString &title,
273  const QString& text,
274  StandardButton button0, StandardButton button1)
275  { return critical(parent, title, text, StandardButtons(button0), button1); }
276 
277  QString buttonText(int button) const;
278  void setButtonText(int button, const QString &text);
279 
280  QString informativeText() const;
281  void setInformativeText(const QString &text);
282 
283 #ifndef QT_NO_TEXTEDIT
284  QString detailedText() const;
285  void setDetailedText(const QString &text);
286 #endif
287 
288  void setWindowTitle(const QString &title);
289  void setWindowModality(Qt::WindowModality windowModality);
290 
291 #ifdef QT3_SUPPORT
292  QT3_SUPPORT_CONSTRUCTOR QMessageBox(const QString &title, const QString &text, Icon icon,
293  int button0, int button1, int button2,
294  QWidget *parent, const char *name, bool modal,
295  Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
296  QT3_SUPPORT_CONSTRUCTOR QMessageBox(QWidget *parent, const char *name);
297 
298  static QT3_SUPPORT QPixmap standardIcon(Icon icon, Qt::GUIStyle);
299  static QT3_SUPPORT int message(const QString &title,
300  const QString& text,
301  const QString& buttonText=QString(),
302  QWidget *parent = 0, const char * = 0) {
303  return QMessageBox::information(parent, title, text,
304  buttonText.isEmpty() ? tr("OK") : buttonText) == 0;
305  }
306  static QT3_SUPPORT bool query(const QString &title,
307  const QString& text,
308  const QString& yesButtonText = QString(),
309  const QString& noButtonText = QString(),
310  QWidget *parent = 0, const char * = 0) {
311  return QMessageBox::information(parent, title, text,
312  yesButtonText.isEmpty() ? tr("OK") : yesButtonText,
313  noButtonText) == 0;
314  }
315 #endif
316 
317  static QPixmap standardIcon(Icon icon);
318 
319 Q_SIGNALS:
320  void buttonClicked(QAbstractButton *button);
321 
322 #ifdef qdoc
323 public Q_SLOTS:
324  int exec();
325 #endif
326 
327 protected:
328  bool event(QEvent *e);
329  void resizeEvent(QResizeEvent *event);
330  void showEvent(QShowEvent *event);
331  void closeEvent(QCloseEvent *event);
332  void keyPressEvent(QKeyEvent *event);
333  void changeEvent(QEvent *event);
334 
335 private:
336  Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
337 
338  Q_DISABLE_COPY(QMessageBox)
339  Q_DECLARE_PRIVATE(QMessageBox)
340 };
341 
342 Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
343 
344 #define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\
345 QString sq = QString::fromLatin1(qVersion()); \
346 if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
347 (sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
348 sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
349 (s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
350 s.section(QChar::fromLatin1('.'),2,2).toInt()) { \
351 if (!qApp){ \
352  new QApplication(argc,argv); \
353 } \
354 QString s = QApplication::tr("Executable '%1' requires Qt "\
355  "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\
356 str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\
357 "Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal("%s", s.toLatin1().data()); }}
358 
359 #endif // QT_NO_MESSAGEBOX
360 
362 
364 
365 #endif // QMESSAGEBOX_H
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
Icon
This enum has the following values:
Definition: qmessagebox.h:76
The QKeyEvent class describes a key event.
Definition: qevent.h:224
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1=NoButton)
Definition: qmessagebox.h:227
void keyPressEvent(QKeyEvent *)
Reimplemented Function
Definition: qdialog.cpp:695
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qdialog.cpp:838
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
static const uint Default
Definition: qsplitter_p.h:61
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qdialog.cpp:1268
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
QString detailedText
the text to be displayed in the details area.
Definition: qmessagebox.h:71
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void closeEvent(QCloseEvent *)
Reimplemented Function
Definition: qdialog.cpp:733
const char * name
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
QSize sizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1160
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
StandardButton Button
Use QMessageBox::StandardButton instead.
Definition: qmessagebox.h:133
void setWindowModality(Qt::WindowModality windowModality)
Definition: qwidget.cpp:2991
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
#define Q_OBJECT
Definition: qobjectdefs.h:157
TextFormat
Definition: qnamespace.h:1310
QString informativeText
the informative text that provides a fuller description for the message
Definition: qmessagebox.h:73
static int question(QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
Definition: qmessagebox.h:242
Definition: qbezier.cpp:259
ButtonRole
Combinations of these roles are as flags used to describe different aspects of their behavior...
Definition: qmessagebox.h:84
bool event(QEvent *e)
Reimplemented Function
Definition: qdialog.cpp:426
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens an information message box with the given title and text in front of the specified parent widge...
Definition: qnamespace.h:54
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
static int critical(QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
Definition: qmessagebox.h:272
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
StandardButton
These enums describe flags for standard buttons.
Definition: qmessagebox.h:100
bool modal
Definition: qmenu_mac.mm:99
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
static int warning(QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
Definition: qmessagebox.h:257
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
WindowModality
Definition: qnamespace.h:1683
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
#define text
Definition: qobjectdefs.h:80
The QList class is a template class that provides lists.
Definition: qdatastream.h:62