Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmessagebox.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMESSAGEBOX_H
5#define QMESSAGEBOX_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qdialog.h>
9#include <QtWidgets/qdialogbuttonbox.h>
10
12
14
15class QAnyStringView;
16class QLabel;
18class QAbstractButton;
19class QCheckBox;
20
21class Q_WIDGETS_EXPORT QMessageBox : public QDialog
22{
26 Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
27 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
28 Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
29#if QT_CONFIG(textedit)
30 Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
31#endif
32 Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
33 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
34 WRITE setTextInteractionFlags)
35 Q_PROPERTY(Options options READ options WRITE setOptions)
36public:
37 // Keep in sync with MessageBoxOption in qplatformdialoghelper.h
38 enum class Option {
39 DontUseNativeDialog = 0x00000001
40 };
42
43 enum Icon {
44 // keep this in sync with QMessageDialogOptions::StandardIcon
45 NoIcon = 0,
46 Information = 1,
47 Warning = 2,
48 Critical = 3,
49 Question = 4
50 };
51 Q_ENUM(Icon)
52
54 // keep this in sync with QDialogButtonBox::ButtonRole and QPlatformDialogHelper::ButtonRole
55 InvalidRole = -1,
65
66 NRoles
67 };
68 Q_ENUM(ButtonRole)
69
71 // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
72 NoButton = 0x00000000,
73 Ok = 0x00000400,
74 Save = 0x00000800,
75 SaveAll = 0x00001000,
76 Open = 0x00002000,
77 Yes = 0x00004000,
78 YesToAll = 0x00008000,
79 No = 0x00010000,
80 NoToAll = 0x00020000,
81 Abort = 0x00040000,
82 Retry = 0x00080000,
83 Ignore = 0x00100000,
84 Close = 0x00200000,
85 Cancel = 0x00400000,
86 Discard = 0x00800000,
87 Help = 0x01000000,
88 Apply = 0x02000000,
89 Reset = 0x04000000,
90 RestoreDefaults = 0x08000000,
91
92 FirstButton = Ok, // internal
93 LastButton = RestoreDefaults, // internal
94
95 YesAll = YesToAll, // obsolete
96 NoAll = NoToAll, // obsolete
97
98 Default = 0x00000100, // obsolete
99 Escape = 0x00000200, // obsolete
100 FlagMask = 0x00000300, // obsolete
101 ButtonMask = ~FlagMask // obsolete
102 };
103 Q_ENUM(StandardButton)
104
105#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
106 typedef StandardButton Button;
107#endif
109 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
110
111 Q_FLAG(StandardButtons)
112
113 explicit QMessageBox(QWidget *parent = nullptr);
114 QMessageBox(Icon icon, const QString &title, const QString &text,
115 StandardButtons buttons = NoButton, QWidget *parent = nullptr,
117 ~QMessageBox();
118
119 void addButton(QAbstractButton *button, ButtonRole role);
120 QPushButton *addButton(const QString &text, ButtonRole role);
121 QPushButton *addButton(StandardButton button);
122 void removeButton(QAbstractButton *button);
123
124 using QDialog::open;
125 void open(QObject *receiver, const char *member);
126
127 QList<QAbstractButton *> buttons() const;
128 ButtonRole buttonRole(QAbstractButton *button) const;
129
130 void setStandardButtons(StandardButtons buttons);
131 StandardButtons standardButtons() const;
132 StandardButton standardButton(QAbstractButton *button) const;
133 QAbstractButton *button(StandardButton which) const;
134
135 QPushButton *defaultButton() const;
137 void setDefaultButton(StandardButton button);
138
139 QAbstractButton *escapeButton() const;
140 void setEscapeButton(QAbstractButton *button);
141 void setEscapeButton(StandardButton button);
142
143 QAbstractButton *clickedButton() const;
144
145 QString text() const;
146 void setText(const QString &text);
147
148 Icon icon() const;
149 void setIcon(Icon);
150
151 QPixmap iconPixmap() const;
152 void setIconPixmap(const QPixmap &pixmap);
153
154 Qt::TextFormat textFormat() const;
155 void setTextFormat(Qt::TextFormat format);
156
157 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
158 Qt::TextInteractionFlags textInteractionFlags() const;
159
160 void setCheckBox(QCheckBox *cb);
161 QCheckBox* checkBox() const;
162
163 void setOption(Option option, bool on = true);
164 bool testOption(Option option) const;
165 void setOptions(Options options);
166 Options options() const;
167
168 static StandardButton information(QWidget *parent, const QString &title,
169 const QString &text, StandardButtons buttons = Ok,
170 StandardButton defaultButton = NoButton);
171#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) // needed as long as we have int overloads
172 inline static StandardButton information(QWidget *parent, const QString &title,
173 const QString& text,
174 StandardButton button0, StandardButton button1 = NoButton)
175 { return information(parent, title, text, StandardButtons(button0), button1); }
176#endif
177
178 static StandardButton question(QWidget *parent, const QString &title,
179 const QString &text, StandardButtons buttons = StandardButtons(Yes | No),
180 StandardButton defaultButton = NoButton);
181#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
182 inline static int question(QWidget *parent, const QString &title,
183 const QString& text,
184 StandardButton button0, StandardButton button1)
185 { return question(parent, title, text, StandardButtons(button0), button1); }
186#endif
187
188 static StandardButton warning(QWidget *parent, const QString &title,
189 const QString &text, StandardButtons buttons = Ok,
190 StandardButton defaultButton = NoButton);
191#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
192 inline static int warning(QWidget *parent, const QString &title,
193 const QString& text,
194 StandardButton button0, StandardButton button1)
195 { return warning(parent, title, text, StandardButtons(button0), button1); }
196#endif
197
198 static StandardButton critical(QWidget *parent, const QString &title,
199 const QString &text, StandardButtons buttons = Ok,
200 StandardButton defaultButton = NoButton);
201#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
202 inline static int critical(QWidget *parent, const QString &title,
203 const QString& text,
204 StandardButton button0, StandardButton button1)
205 { return critical(parent, title, text, StandardButtons(button0), button1); }
206#endif
207
208 static void about(QWidget *parent, const QString &title, const QString &text);
209 static void aboutQt(QWidget *parent, const QString &title = QString());
210
211#if QT_DEPRECATED_SINCE(6,2)
212 // the following functions are obsolete:
213 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
214 QMessageBox(const QString &title, const QString &text, Icon icon,
215 int button0, int button1, int button2,
216 QWidget *parent = nullptr,
217 Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
218
219 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
220 static int information(QWidget *parent, const QString &title,
221 const QString& text,
222 int button0, int button1 = 0, int button2 = 0);
223 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
224 static int information(QWidget *parent, const QString &title,
225 const QString& text,
226 const QString& button0Text,
227 const QString& button1Text = QString(),
228 const QString& button2Text = QString(),
229 int defaultButtonNumber = 0,
230 int escapeButtonNumber = -1);
231
232 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
233 static int question(QWidget *parent, const QString &title,
234 const QString& text,
235 int button0, int button1 = 0, int button2 = 0);
236 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
237 static int question(QWidget *parent, const QString &title,
238 const QString& text,
239 const QString& button0Text,
240 const QString& button1Text = QString(),
241 const QString& button2Text = QString(),
242 int defaultButtonNumber = 0,
243 int escapeButtonNumber = -1);
244
245 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
246 static int warning(QWidget *parent, const QString &title,
247 const QString& text,
248 int button0, int button1, int button2 = 0);
249 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
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
258 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
259 static int critical(QWidget *parent, const QString &title,
260 const QString& text,
261 int button0, int button1, int button2 = 0);
262 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
263 static int critical(QWidget *parent, const QString &title,
264 const QString& text,
265 const QString& button0Text,
266 const QString& button1Text = QString(),
267 const QString& button2Text = QString(),
268 int defaultButtonNumber = 0,
269 int escapeButtonNumber = -1);
270
271 QT_DEPRECATED_VERSION_X_6_2("Use button() and QPushButton::text() instead.")
272 QString buttonText(int button) const;
273 QT_DEPRECATED_VERSION_X_6_2("Use addButton() instead.")
274 void setButtonText(int button, const QString &text);
275#endif
276
277 QString informativeText() const;
278 void setInformativeText(const QString &text);
279
280#if QT_CONFIG(textedit)
281 QString detailedText() const;
282 void setDetailedText(const QString &text);
283#endif
284
285 void setWindowTitle(const QString &title);
286 void setWindowModality(Qt::WindowModality windowModality);
287
288#if QT_DEPRECATED_SINCE(6,2)
289 QT_DEPRECATED_VERSION_X_6_2("Use QStyle::standardIcon() instead.")
290 static QPixmap standardIcon(Icon icon);
291#endif
292
295
296#ifdef Q_QDOC
297public Q_SLOTS:
298 int exec() override;
299#endif
300
301protected:
302 bool event(QEvent *e) override;
303 void resizeEvent(QResizeEvent *event) override;
304 void showEvent(QShowEvent *event) override;
305 void closeEvent(QCloseEvent *event) override;
306 void keyPressEvent(QKeyEvent *event) override;
307 void changeEvent(QEvent *event) override;
308
309private:
310 Q_DISABLE_COPY(QMessageBox)
311 Q_DECLARE_PRIVATE(QMessageBox)
312};
313
314Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
315
316Q_WIDGETS_EXPORT void qRequireVersion(int argc, char *argv[], QAnyStringView req);
317
318#define QT_REQUIRE_VERSION(argc, argv, str) qRequireVersion(argc, argv, str);
319
321
322#endif // QMESSAGEBOX_H
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
\inmodule QtCore
The QCheckBox widget provides a checkbox with a text label.
Definition qcheckbox.h:19
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
virtual void open()
Definition qdialog.cpp:503
\inmodule QtCore
Definition qcoreevent.h:45
The QKeyEvent class describes a key event.
Definition qevent.h:424
The QLabel widget provides a text or image display.
Definition qlabel.h:20
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition qmessagebox.h:22
void buttonClicked(QAbstractButton *button)
This signal is emitted whenever a button is clicked inside the QMessageBox.
Icon
This enum has the following values:
Definition qmessagebox.h:43
\inmodule QtCore
Definition qobject.h:103
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QString text
QPushButton * button
[2]
Combined button and popup list for selecting options.
Definition qcompare.h:63
WindowModality
TextFormat
@ MSWindowsFixedSizeDialogHint
Definition qnamespace.h:221
@ Dialog
Definition qnamespace.h:208
@ ButtonMask
@ Ok
Definition qbezier.cpp:173
@ Discard
Definition qbezier.cpp:174
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
Button
Q_WIDGETS_EXPORT void qRequireVersion(int argc, char *argv[], QAnyStringView req)
GLfloat GLfloat f
GLbitfield flags
GLint GLsizei GLsizei GLenum format
struct _cl_event * event
GLuint GLenum option
QDebug warning(QAnyStringView fileName, int lineNumber)
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:27
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_2(text)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SLOTS
#define Q_SIGNALS
file open(QIODevice::ReadOnly)
QString title
[35]
dialog exec()
msgBox setInformativeText("Do you want to save your changes?")
msgBox setDefaultButton(QMessageBox::Save)
msgBox setStandardButtons(QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel)
myAction setIcon(SomeIcon)
widget render & pixmap
insertRed setText("insert red text")