File indexing completed on 2026-09-25 09:26:26
0001
0002
0003
0004
0005 #ifndef QMESSAGEBOX_H
0006 #define QMESSAGEBOX_H
0007
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtWidgets/qdialog.h>
0010 #include <QtWidgets/qdialogbuttonbox.h>
0011
0012 QT_REQUIRE_CONFIG(messagebox);
0013
0014 QT_BEGIN_NAMESPACE
0015
0016 class QAnyStringView;
0017 class QLabel;
0018 class QMessageBoxPrivate;
0019 class QAbstractButton;
0020 class QCheckBox;
0021
0022 class Q_WIDGETS_EXPORT QMessageBox : public QDialog
0023 {
0024 Q_OBJECT
0025 Q_PROPERTY(QString text READ text WRITE setText)
0026 Q_PROPERTY(Icon icon READ icon WRITE setIcon)
0027 Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
0028 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
0029 Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
0030 #if QT_CONFIG(textedit)
0031 Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
0032 #endif
0033 Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
0034 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
0035 WRITE setTextInteractionFlags)
0036 Q_PROPERTY(Options options READ options WRITE setOptions)
0037 public:
0038
0039 enum class Option {
0040 DontUseNativeDialog = 0x00000001
0041 };
0042 Q_FLAG(Option)
0043
0044 enum Icon {
0045
0046 NoIcon = 0,
0047 Information = 1,
0048 Warning = 2,
0049 Critical = 3,
0050 Question = 4
0051 };
0052 Q_ENUM(Icon)
0053
0054 enum ButtonRole {
0055
0056 InvalidRole = -1,
0057 AcceptRole,
0058 RejectRole,
0059 DestructiveRole,
0060 ActionRole,
0061 HelpRole,
0062 YesRole,
0063 NoRole,
0064 ResetRole,
0065 ApplyRole,
0066
0067 NRoles
0068 };
0069 Q_ENUM(ButtonRole)
0070
0071 enum StandardButton {
0072
0073 NoButton = 0x00000000,
0074 Ok = 0x00000400,
0075 Save = 0x00000800,
0076 SaveAll = 0x00001000,
0077 Open = 0x00002000,
0078 Yes = 0x00004000,
0079 YesToAll = 0x00008000,
0080 No = 0x00010000,
0081 NoToAll = 0x00020000,
0082 Abort = 0x00040000,
0083 Retry = 0x00080000,
0084 Ignore = 0x00100000,
0085 Close = 0x00200000,
0086 Cancel = 0x00400000,
0087 Discard = 0x00800000,
0088 Help = 0x01000000,
0089 Apply = 0x02000000,
0090 Reset = 0x04000000,
0091 RestoreDefaults = 0x08000000,
0092
0093 FirstButton = Ok,
0094 LastButton = RestoreDefaults,
0095
0096 YesAll = YesToAll,
0097 NoAll = NoToAll,
0098
0099 Default = 0x00000100,
0100 Escape = 0x00000200,
0101 FlagMask = 0x00000300,
0102 ButtonMask = ~FlagMask
0103 };
0104 Q_ENUM(StandardButton)
0105
0106 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0107 typedef StandardButton Button;
0108 #endif
0109 Q_DECLARE_FLAGS(Options, Option)
0110 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
0111
0112 Q_FLAG(StandardButtons)
0113
0114 explicit QMessageBox(QWidget *parent = nullptr);
0115 QMessageBox(Icon icon, const QString &title, const QString &text,
0116 StandardButtons buttons = NoButton, QWidget *parent = nullptr,
0117 Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
0118 ~QMessageBox();
0119
0120 void addButton(QAbstractButton *button, ButtonRole role);
0121 QPushButton *addButton(const QString &text, ButtonRole role);
0122 QPushButton *addButton(StandardButton button);
0123 void removeButton(QAbstractButton *button);
0124
0125 using QDialog::open;
0126 void open(QObject *receiver, const char *member);
0127
0128 QList<QAbstractButton *> buttons() const;
0129 ButtonRole buttonRole(QAbstractButton *button) const;
0130
0131 void setStandardButtons(StandardButtons buttons);
0132 StandardButtons standardButtons() const;
0133 StandardButton standardButton(QAbstractButton *button) const;
0134 QAbstractButton *button(StandardButton which) const;
0135
0136 QPushButton *defaultButton() const;
0137 void setDefaultButton(QPushButton *button);
0138 void setDefaultButton(StandardButton button);
0139
0140 QAbstractButton *escapeButton() const;
0141 void setEscapeButton(QAbstractButton *button);
0142 void setEscapeButton(StandardButton button);
0143
0144 QAbstractButton *clickedButton() const;
0145
0146 QString text() const;
0147 void setText(const QString &text);
0148
0149 Icon icon() const;
0150 void setIcon(Icon);
0151
0152 QPixmap iconPixmap() const;
0153 void setIconPixmap(const QPixmap &pixmap);
0154
0155 Qt::TextFormat textFormat() const;
0156 void setTextFormat(Qt::TextFormat format);
0157
0158 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
0159 Qt::TextInteractionFlags textInteractionFlags() const;
0160
0161 void setCheckBox(QCheckBox *cb);
0162 QCheckBox* checkBox() const;
0163
0164 void setOption(Option option, bool on = true);
0165 bool testOption(Option option) const;
0166 void setOptions(Options options);
0167 Options options() const;
0168
0169 static StandardButton information(QWidget *parent, const QString &title,
0170 const QString &text, StandardButtons buttons = Ok,
0171 StandardButton defaultButton = NoButton);
0172 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0173 inline static StandardButton information(QWidget *parent, const QString &title,
0174 const QString& text,
0175 StandardButton button0, StandardButton button1 = NoButton)
0176 { return information(parent, title, text, StandardButtons(button0), button1); }
0177 #endif
0178
0179 static StandardButton question(QWidget *parent, const QString &title,
0180 const QString &text, StandardButtons buttons = StandardButtons(Yes | No),
0181 StandardButton defaultButton = NoButton);
0182 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0183 inline static int question(QWidget *parent, const QString &title,
0184 const QString& text,
0185 StandardButton button0, StandardButton button1)
0186 { return question(parent, title, text, StandardButtons(button0), button1); }
0187 #endif
0188
0189 static StandardButton warning(QWidget *parent, const QString &title,
0190 const QString &text, StandardButtons buttons = Ok,
0191 StandardButton defaultButton = NoButton);
0192 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0193 inline static int warning(QWidget *parent, const QString &title,
0194 const QString& text,
0195 StandardButton button0, StandardButton button1)
0196 { return warning(parent, title, text, StandardButtons(button0), button1); }
0197 #endif
0198
0199 static StandardButton critical(QWidget *parent, const QString &title,
0200 const QString &text, StandardButtons buttons = Ok,
0201 StandardButton defaultButton = NoButton);
0202 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0203 inline static int critical(QWidget *parent, const QString &title,
0204 const QString& text,
0205 StandardButton button0, StandardButton button1)
0206 { return critical(parent, title, text, StandardButtons(button0), button1); }
0207 #endif
0208
0209 static void about(QWidget *parent, const QString &title, const QString &text);
0210 static void aboutQt(QWidget *parent, const QString &title = QString());
0211
0212 #if QT_DEPRECATED_SINCE(6,2)
0213
0214 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0215 QMessageBox(const QString &title, const QString &text, Icon icon,
0216 int button0, int button1, int button2,
0217 QWidget *parent = nullptr,
0218 Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
0219
0220 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0221 static int information(QWidget *parent, const QString &title,
0222 const QString& text,
0223 int button0, int button1 = 0, int button2 = 0);
0224 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0225 static int information(QWidget *parent, const QString &title,
0226 const QString& text,
0227 const QString& button0Text,
0228 const QString& button1Text = QString(),
0229 const QString& button2Text = QString(),
0230 int defaultButtonNumber = 0,
0231 int escapeButtonNumber = -1);
0232
0233 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0234 static int question(QWidget *parent, const QString &title,
0235 const QString& text,
0236 int button0, int button1 = 0, int button2 = 0);
0237 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0238 static int question(QWidget *parent, const QString &title,
0239 const QString& text,
0240 const QString& button0Text,
0241 const QString& button1Text = QString(),
0242 const QString& button2Text = QString(),
0243 int defaultButtonNumber = 0,
0244 int escapeButtonNumber = -1);
0245
0246 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0247 static int warning(QWidget *parent, const QString &title,
0248 const QString& text,
0249 int button0, int button1, int button2 = 0);
0250 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0251 static int warning(QWidget *parent, const QString &title,
0252 const QString& text,
0253 const QString& button0Text,
0254 const QString& button1Text = QString(),
0255 const QString& button2Text = QString(),
0256 int defaultButtonNumber = 0,
0257 int escapeButtonNumber = -1);
0258
0259 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0260 static int critical(QWidget *parent, const QString &title,
0261 const QString& text,
0262 int button0, int button1, int button2 = 0);
0263 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
0264 static int critical(QWidget *parent, const QString &title,
0265 const QString& text,
0266 const QString& button0Text,
0267 const QString& button1Text = QString(),
0268 const QString& button2Text = QString(),
0269 int defaultButtonNumber = 0,
0270 int escapeButtonNumber = -1);
0271
0272 QT_DEPRECATED_VERSION_X_6_2("Use button() and QPushButton::text() instead.")
0273 QString buttonText(int button) const;
0274 QT_DEPRECATED_VERSION_X_6_2("Use addButton() instead.")
0275 void setButtonText(int button, const QString &text);
0276 #endif
0277
0278 QString informativeText() const;
0279 void setInformativeText(const QString &text);
0280
0281 #if QT_CONFIG(textedit)
0282 QString detailedText() const;
0283 void setDetailedText(const QString &text);
0284 #endif
0285
0286 void setWindowTitle(const QString &title);
0287 void setWindowModality(Qt::WindowModality windowModality);
0288
0289 #if QT_DEPRECATED_SINCE(6,2)
0290 QT_DEPRECATED_VERSION_X_6_2("Use QStyle::standardIcon() instead.")
0291 static QPixmap standardIcon(Icon icon);
0292 #endif
0293
0294 Q_SIGNALS:
0295 void buttonClicked(QAbstractButton *button);
0296
0297 #ifdef Q_QDOC
0298 public Q_SLOTS:
0299 int exec() override;
0300 #endif
0301
0302 protected:
0303 bool event(QEvent *e) override;
0304 void resizeEvent(QResizeEvent *event) override;
0305 void showEvent(QShowEvent *event) override;
0306 void closeEvent(QCloseEvent *event) override;
0307 void keyPressEvent(QKeyEvent *event) override;
0308 void changeEvent(QEvent *event) override;
0309
0310 private:
0311 Q_DISABLE_COPY(QMessageBox)
0312 Q_DECLARE_PRIVATE(QMessageBox)
0313 };
0314
0315 Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
0316
0317 Q_WIDGETS_EXPORT void qRequireVersion(int argc, char *argv[], QAnyStringView req);
0318
0319 #define QT_REQUIRE_VERSION(argc, argv, str) qRequireVersion(argc, argv, str);
0320
0321 QT_END_NAMESPACE
0322
0323 #endif