- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qmessagebox.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QMESSAGEBOX_H
    00043 #define QMESSAGEBOX_H
    00044
    00045 #include <QtGui/qdialog.h>
    00046
    00047 QT_BEGIN_HEADER
    00048
    00049 QT_BEGIN_NAMESPACE
    00050
    00051 QT_MODULE(Gui)
    00052
    00053 #ifndef QT_NO_MESSAGEBOX
    00054
    00055 class QLabel;
    00056 class QMessageBoxPrivate;
    00057 class QAbstractButton;
    00058
    00059 class Q_GUI_EXPORT QMessageBox : public QDialog
    00060 {
    00061     Q_OBJECT
    00062     Q_ENUMS(Icon)
    00063     Q_FLAGS(StandardButtons)
    00064     Q_PROPERTY(QString text READ text WRITE setText)
    00065     // ### Qt 5: Rename 'icon' 'standardIcon' and 'iconPixmap' 'icon' (and use QIcon?)
    00066     Q_PROPERTY(Icon icon READ icon WRITE setIcon)
    00067     Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
    00068     Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
    00069     Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
    00070 #ifndef QT_NO_TEXTEDIT
    00071     Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
    00072 #endif
    00073     Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
    00074
    00075 public:
    00076     enum Icon {
    00077         NoIcon = 0,
    00078         Information = 1,
    00079         Warning = 2,
    00080         Critical = 3,
    00081         Question = 4
    00082     };
    00083
    00084     enum ButtonRole {
    00085         // keep this in sync with QDialogButtonBox::ButtonRole
    00086         InvalidRole = -1,
    00087         AcceptRole,
    00088         RejectRole,
    00089         DestructiveRole,
    00090         ActionRole,
    00091         HelpRole,
    00092         YesRole,
    00093         NoRole,
    00094         ResetRole,
    00095         ApplyRole,
    00096
    00097         NRoles
    00098     };
    00099
    00100     enum StandardButton {
    00101         // keep this in sync with QDialogButtonBox::StandardButton
    00102         NoButton           = 0x00000000,
    00103         Ok                 = 0x00000400,
    00104         Save               = 0x00000800,
    00105         SaveAll            = 0x00001000,
    00106         Open               = 0x00002000,
    00107         Yes                = 0x00004000,
    00108         YesToAll           = 0x00008000,
    00109         No                 = 0x00010000,
    00110         NoToAll            = 0x00020000,
    00111         Abort              = 0x00040000,
    00112         Retry              = 0x00080000,
    00113         Ignore             = 0x00100000,
    00114         Close              = 0x00200000,
    00115         Cancel             = 0x00400000,
    00116         Discard            = 0x00800000,
    00117         Help               = 0x01000000,
    00118         Apply              = 0x02000000,
    00119         Reset              = 0x04000000,
    00120         RestoreDefaults    = 0x08000000,
    00121
    00122         FirstButton        = Ok,                // internal
    00123         LastButton         = RestoreDefaults,   // internal
    00124
    00125         YesAll             = YesToAll,          // obsolete
    00126         NoAll              = NoToAll,           // obsolete
    00127
    00128         Default            = 0x00000100,        // obsolete
    00129         Escape             = 0x00000200,        // obsolete
    00130         FlagMask           = 0x00000300,        // obsolete
    00131         ButtonMask         = ~FlagMask          // obsolete
    00132     };
    00133     typedef StandardButton Button;  // obsolete
    00134
    00135     Q_DECLARE_FLAGS(StandardButtons, StandardButton)
    00136
    00137     explicit QMessageBox(QWidget *parent = 0);
    00138     QMessageBox(Icon icon, const QString &title, const QString &text,
    00139                 StandardButtons buttons = NoButton, QWidget *parent = 0,
    00140                 Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    00141     ~QMessageBox();
    00142
    00143     void addButton(QAbstractButton *button, ButtonRole role);
    00144     QPushButton *addButton(const QString &text, ButtonRole role);
    00145     QPushButton *addButton(StandardButton button);
    00146     void removeButton(QAbstractButton *button);
    00147
    00148 #ifdef Q_WS_WINCE
    00149     void setVisible(bool visible);
    00150 #endif
    00151
    00152 #ifdef Q_NO_USING_KEYWORD
    00153 #ifndef Q_QDOC
    00154     void open() { QDialog::open(); }
    00155 #endif
    00156 #else
    00157     using QDialog::open;
    00158 #endif
    00159     void open(QObject *receiver, const char *member);
    00160
    00161     QList<QAbstractButton *> buttons() const;
    00162     ButtonRole buttonRole(QAbstractButton *button) const;
    00163
    00164     void setStandardButtons(StandardButtons buttons);
    00165     StandardButtons standardButtons() const;
    00166     StandardButton standardButton(QAbstractButton *button) const;
    00167     QAbstractButton *button(StandardButton which) const;
    00168
    00169     QPushButton *defaultButton() const;
    00170     void setDefaultButton(QPushButton *button);
    00171     void setDefaultButton(StandardButton button);
    00172
    00173     QAbstractButton *escapeButton() const;
    00174     void setEscapeButton(QAbstractButton *button);
    00175     void setEscapeButton(StandardButton button);
    00176
    00177     QAbstractButton *clickedButton() const;
    00178
    00179     QString text() const;
    00180     void setText(const QString &text);
    00181
    00182     Icon icon() const;
    00183     void setIcon(Icon);
    00184
    00185     QPixmap iconPixmap() const;
    00186     void setIconPixmap(const QPixmap &pixmap);
    00187
    00188     Qt::TextFormat textFormat() const;
    00189     void setTextFormat(Qt::TextFormat format);
    00190
    00191     static StandardButton information(QWidget *parent, const QString &title,
    00192          const QString &text, StandardButtons buttons = Ok,
    00193          StandardButton defaultButton = NoButton);
    00194     // ### Qt 5: Replace Ok with Yes|No in question() function.
    00195     //     Also consider if Ok == Yes and Cancel == No.
    00196     static StandardButton question(QWidget *parent, const QString &title,
    00197          const QString &text, StandardButtons buttons = Ok,
    00198          StandardButton defaultButton = NoButton);
    00199     static StandardButton warning(QWidget *parent, const QString &title,
    00200          const QString &text, StandardButtons buttons = Ok,
    00201          StandardButton defaultButton = NoButton);
    00202     static StandardButton critical(QWidget *parent, const QString &title,
    00203          const QString &text, StandardButtons buttons = Ok,
    00204          StandardButton defaultButton = NoButton);
    00205     static void about(QWidget *parent, const QString &title, const QString &text);
    00206     static void aboutQt(QWidget *parent, const QString &title = QString());
    00207
    00208     QSize sizeHint() const;
    00209
    00210     // the following functions are obsolete:
    00211
    00212     QMessageBox(const QString &title, const QString &text, Icon icon,
    00213                   int button0, int button1, int button2,
    00214                   QWidget *parent = 0,
    00215                   Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    00216
    00217     static int information(QWidget *parent, const QString &title,
    00218                            const QString& text,
    00219                            int button0, int button1 = 0, int button2 = 0);
    00220     static int information(QWidget *parent, const QString &title,
    00221                            const QString& text,
    00222                            const QString& button0Text,
    00223                            const QString& button1Text = QString(),
    00224                            const QString& button2Text = QString(),
    00225                            int defaultButtonNumber = 0,
    00226                            int escapeButtonNumber = -1);
    00227     inline static StandardButton information(QWidget *parent, const QString &title,
    00228                                   const QString& text,
    00229                                   StandardButton button0, StandardButton button1 = NoButton)
    00230     { return information(parent, title, text, StandardButtons(button0), button1); }
    00231
    00232     static int question(QWidget *parent, const QString &title,
    00233                         const QString& text,
    00234                         int button0, int button1 = 0, int button2 = 0);
    00235     static int question(QWidget *parent, const QString &title,
    00236                         const QString& text,
    00237                         const QString& button0Text,
    00238                         const QString& button1Text = QString(),
    00239                         const QString& button2Text = QString(),
    00240                         int defaultButtonNumber = 0,
    00241                         int escapeButtonNumber = -1);
    00242     inline static int question(QWidget *parent, const QString &title,
    00243                                const QString& text,
    00244                                StandardButton button0, StandardButton button1)
    00245     { return question(parent, title, text, StandardButtons(button0), button1); }
    00246
    00247     static int warning(QWidget *parent, const QString &title,
    00248                        const QString& text,
    00249                        int button0, int button1, int button2 = 0);
    00250     static int warning(QWidget *parent, const QString &title,
    00251                        const QString& text,
    00252                        const QString& button0Text,
    00253                        const QString& button1Text = QString(),
    00254                        const QString& button2Text = QString(),
    00255                        int defaultButtonNumber = 0,
    00256                        int escapeButtonNumber = -1);
    00257     inline static int warning(QWidget *parent, const QString &title,
    00258                               const QString& text,
    00259                               StandardButton button0, StandardButton button1)
    00260     { return warning(parent, title, text, StandardButtons(button0), button1); }
    00261
    00262     static int critical(QWidget *parent, const QString &title,
    00263                         const QString& text,
    00264                         int button0, int button1, int button2 = 0);
    00265     static int critical(QWidget *parent, const QString &title,
    00266                         const QString& text,
    00267                         const QString& button0Text,
    00268                         const QString& button1Text = QString(),
    00269                         const QString& button2Text = QString(),
    00270                         int defaultButtonNumber = 0,
    00271                         int escapeButtonNumber = -1);
    00272     inline static int critical(QWidget *parent, const QString &title,
    00273                                const QString& text,
    00274                                StandardButton button0, StandardButton button1)
    00275     { return critical(parent, title, text, StandardButtons(button0), button1); }
    00276
    00277     QString buttonText(int button) const;
    00278     void setButtonText(int button, const QString &text);
    00279
    00280     QString informativeText() const;
    00281     void setInformativeText(const QString &text);
    00282
    00283 #ifndef QT_NO_TEXTEDIT
    00284     QString detailedText() const;
    00285     void setDetailedText(const QString &text);
    00286 #endif
    00287
    00288     void setWindowTitle(const QString &title);
    00289     void setWindowModality(Qt::WindowModality windowModality);
    00290
    00291 #ifdef QT3_SUPPORT
    00292     QT3_SUPPORT_CONSTRUCTOR QMessageBox(const QString &title, const QString &text, Icon icon,
    00293                                           int button0, int button1, int button2,
    00294                                           QWidget *parent, const char *name, bool modal,
    00295                                            Qt::WindowFlags f =  Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    00296     QT3_SUPPORT_CONSTRUCTOR QMessageBox(QWidget *parent, const char *name);
    00297
    00298     static QT3_SUPPORT QPixmap standardIcon(Icon icon, Qt::GUIStyle);
    00299     static QT3_SUPPORT int message(const QString &title,
    00300                                    const QString& text,
    00301                                    const QString& buttonText=QString(),
    00302                                    QWidget *parent = 0, const char * = 0) {
    00303         return QMessageBox::information(parent, title, text,
    00304                                         buttonText.isEmpty() ? tr("OK") : buttonText) == 0;
    00305     }
    00306     static QT3_SUPPORT bool query(const QString &title,
    00307                                   const QString& text,
    00308                                   const QString& yesButtonText = QString(),
    00309                                   const QString& noButtonText = QString(),
    00310                                   QWidget *parent = 0, const char * = 0) {
    00311         return QMessageBox::information(parent, title, text,
    00312                                         yesButtonText.isEmpty() ? tr("OK") : yesButtonText,
    00313                                         noButtonText) == 0;
    00314     }
    00315 #endif
    00316
    00317     static QPixmap standardIcon(Icon icon);
    00318
    00319 Q_SIGNALS:
    00320     void buttonClicked(QAbstractButton *button);
    00321
    00322 #ifdef qdoc
    00323 public Q_SLOTS:
    00324     int exec();
    00325 #endif
    00326
    00327 protected:
    00328     bool event(QEvent *e);
    00329     void resizeEvent(QResizeEvent *event);
    00330     void showEvent(QShowEvent *event);
    00331     void closeEvent(QCloseEvent *event);
    00332     void keyPressEvent(QKeyEvent *event);
    00333     void changeEvent(QEvent *event);
    00334
    00335 private:
    00336     Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
    00337
    00338     Q_DISABLE_COPY(QMessageBox)
    00339     Q_DECLARE_PRIVATE(QMessageBox)
    00340 };
    00341
    00342 Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
    00343
    00344 #define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\
    00345 QString sq = QString::fromLatin1(qVersion()); \
    00346 if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
    00347 (sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
    00348 sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\
    00349 (s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\
    00350 s.section(QChar::fromLatin1('.'),2,2).toInt()) { \
    00351 if (!qApp){ \
    00352     new QApplication(argc,argv); \
    00353 } \
    00354 QString s = QApplication::tr("Executable '%1' requires Qt "\
    00355  "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\
    00356 str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\
    00357 "Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal("%s", s.toLatin1().data()); }}
    00358
    00359 #endif // QT_NO_MESSAGEBOX
    00360
    00361 QT_END_NAMESPACE
    00362
    00363 QT_END_HEADER
    00364
    00365 #endif // QMESSAGEBOX_H