Qt 6.x
The Qt SDK
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
11
13
14class QAnyStringView;
15class QLabel;
17class QAbstractButton;
18class QCheckBox;
19
20class Q_WIDGETS_EXPORT QMessageBox : public QDialog
21{
24 Q_PROPERTY(Icon icon READ icon WRITE setIcon)
25 Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
26 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
27 Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons)
28#if QT_CONFIG(textedit)
29 Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText)
30#endif
31 Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText)
32 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
33 WRITE setTextInteractionFlags)
34 Q_PROPERTY(Options options READ options WRITE setOptions)
35public:
36 // Keep in sync with MessageBoxOption in qplatformdialoghelper.h
37 enum class Option : quint8 {
38 DontUseNativeDialog = 0x00000001
39 };
41
42 enum Icon {
43 // keep this in sync with QMessageDialogOptions::StandardIcon
44 NoIcon = 0,
45 Information = 1,
46 Warning = 2,
47 Critical = 3,
48 Question = 4
49 };
50 Q_ENUM(Icon)
51
53 // keep this in sync with QDialogButtonBox::ButtonRole and QPlatformDialogHelper::ButtonRole
54 InvalidRole = -1,
64
65 NRoles
66 };
67
69 // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
70 NoButton = 0x00000000,
71 Ok = 0x00000400,
72 Save = 0x00000800,
73 SaveAll = 0x00001000,
74 Open = 0x00002000,
75 Yes = 0x00004000,
76 YesToAll = 0x00008000,
77 No = 0x00010000,
78 NoToAll = 0x00020000,
79 Abort = 0x00040000,
80 Retry = 0x00080000,
81 Ignore = 0x00100000,
82 Close = 0x00200000,
83 Cancel = 0x00400000,
84 Discard = 0x00800000,
85 Help = 0x01000000,
86 Apply = 0x02000000,
87 Reset = 0x04000000,
88 RestoreDefaults = 0x08000000,
89
90 FirstButton = Ok, // internal
91 LastButton = RestoreDefaults, // internal
92
93 YesAll = YesToAll, // obsolete
94 NoAll = NoToAll, // obsolete
95
96 Default = 0x00000100, // obsolete
97 Escape = 0x00000200, // obsolete
98 FlagMask = 0x00000300, // obsolete
99 ButtonMask = ~FlagMask // obsolete
100 };
101#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
102 typedef StandardButton Button;
103#endif
105 Q_DECLARE_FLAGS(StandardButtons, StandardButton)
106
107 Q_FLAG(StandardButtons)
108
109 explicit QMessageBox(QWidget *parent = nullptr);
110 QMessageBox(Icon icon, const QString &title, const QString &text,
111 StandardButtons buttons = NoButton, QWidget *parent = nullptr,
113 ~QMessageBox();
114
115 void addButton(QAbstractButton *button, ButtonRole role);
116 QPushButton *addButton(const QString &text, ButtonRole role);
117 QPushButton *addButton(StandardButton button);
118 void removeButton(QAbstractButton *button);
119
120 using QDialog::open;
121 void open(QObject *receiver, const char *member);
122
123 QList<QAbstractButton *> buttons() const;
124 ButtonRole buttonRole(QAbstractButton *button) const;
125
126 void setStandardButtons(StandardButtons buttons);
127 StandardButtons standardButtons() const;
128 StandardButton standardButton(QAbstractButton *button) const;
129 QAbstractButton *button(StandardButton which) const;
130
131 QPushButton *defaultButton() const;
133 void setDefaultButton(StandardButton button);
134
135 QAbstractButton *escapeButton() const;
136 void setEscapeButton(QAbstractButton *button);
137 void setEscapeButton(StandardButton button);
138
139 QAbstractButton *clickedButton() const;
140
141 QString text() const;
142 void setText(const QString &text);
143
144 Icon icon() const;
145 void setIcon(Icon);
146
147 QPixmap iconPixmap() const;
148 void setIconPixmap(const QPixmap &pixmap);
149
150 Qt::TextFormat textFormat() const;
151 void setTextFormat(Qt::TextFormat format);
152
153 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
154 Qt::TextInteractionFlags textInteractionFlags() const;
155
156 void setCheckBox(QCheckBox *cb);
157 QCheckBox* checkBox() const;
158
159 void setOption(Option option, bool on = true);
160 bool testOption(Option option) const;
161 void setOptions(Options options);
162 Options options() const;
163
164 static StandardButton information(QWidget *parent, const QString &title,
165 const QString &text, StandardButtons buttons = Ok,
166 StandardButton defaultButton = NoButton);
167#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) // needed as long as we have int overloads
168 inline static StandardButton information(QWidget *parent, const QString &title,
169 const QString& text,
170 StandardButton button0, StandardButton button1 = NoButton)
171 { return information(parent, title, text, StandardButtons(button0), button1); }
172#endif
173
174 static StandardButton question(QWidget *parent, const QString &title,
175 const QString &text, StandardButtons buttons = StandardButtons(Yes | No),
176 StandardButton defaultButton = NoButton);
177#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
178 inline static int question(QWidget *parent, const QString &title,
179 const QString& text,
180 StandardButton button0, StandardButton button1)
181 { return question(parent, title, text, StandardButtons(button0), button1); }
182#endif
183
184 static StandardButton warning(QWidget *parent, const QString &title,
185 const QString &text, StandardButtons buttons = Ok,
186 StandardButton defaultButton = NoButton);
187#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
188 inline static int warning(QWidget *parent, const QString &title,
189 const QString& text,
190 StandardButton button0, StandardButton button1)
191 { return warning(parent, title, text, StandardButtons(button0), button1); }
192#endif
193
194 static StandardButton critical(QWidget *parent, const QString &title,
195 const QString &text, StandardButtons buttons = Ok,
196 StandardButton defaultButton = NoButton);
197#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
198 inline static int critical(QWidget *parent, const QString &title,
199 const QString& text,
200 StandardButton button0, StandardButton button1)
201 { return critical(parent, title, text, StandardButtons(button0), button1); }
202#endif
203
204 static void about(QWidget *parent, const QString &title, const QString &text);
205 static void aboutQt(QWidget *parent, const QString &title = QString());
206
207#if QT_DEPRECATED_SINCE(6,2)
208 // the following functions are obsolete:
209 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
210 QMessageBox(const QString &title, const QString &text, Icon icon,
211 int button0, int button1, int button2,
212 QWidget *parent = nullptr,
213 Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
214
215 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
216 static int information(QWidget *parent, const QString &title,
217 const QString& text,
218 int button0, int button1 = 0, int button2 = 0);
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 const QString& button0Text,
223 const QString& button1Text = QString(),
224 const QString& button2Text = QString(),
225 int defaultButtonNumber = 0,
226 int escapeButtonNumber = -1);
227
228 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
229 static int question(QWidget *parent, const QString &title,
230 const QString& text,
231 int button0, int button1 = 0, int button2 = 0);
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 const QString& button0Text,
236 const QString& button1Text = QString(),
237 const QString& button2Text = QString(),
238 int defaultButtonNumber = 0,
239 int escapeButtonNumber = -1);
240
241 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
242 static int warning(QWidget *parent, const QString &title,
243 const QString& text,
244 int button0, int button1, int button2 = 0);
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 const QString& button0Text,
249 const QString& button1Text = QString(),
250 const QString& button2Text = QString(),
251 int defaultButtonNumber = 0,
252 int escapeButtonNumber = -1);
253
254 QT_DEPRECATED_VERSION_X_6_2("Use the overload taking StandardButtons instead.")
255 static int critical(QWidget *parent, const QString &title,
256 const QString& text,
257 int button0, int button1, int button2 = 0);
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 const QString& button0Text,
262 const QString& button1Text = QString(),
263 const QString& button2Text = QString(),
264 int defaultButtonNumber = 0,
265 int escapeButtonNumber = -1);
266
267 QT_DEPRECATED_VERSION_X_6_2("Use button() and QPushButton::text() instead.")
268 QString buttonText(int button) const;
269 QT_DEPRECATED_VERSION_X_6_2("Use addButton() instead.")
270 void setButtonText(int button, const QString &text);
271#endif
272
273 QString informativeText() const;
274 void setInformativeText(const QString &text);
275
276#if QT_CONFIG(textedit)
277 QString detailedText() const;
278 void setDetailedText(const QString &text);
279#endif
280
281 void setWindowTitle(const QString &title);
282 void setWindowModality(Qt::WindowModality windowModality);
283
284#if QT_DEPRECATED_SINCE(6,2)
285 QT_DEPRECATED_VERSION_X_6_2("Use QStyle::standardIcon() instead.")
286 static QPixmap standardIcon(Icon icon);
287#endif
288
291
292#ifdef Q_QDOC
293public Q_SLOTS:
294 int exec() override;
295#endif
296
297protected:
298 bool event(QEvent *e) override;
299 void resizeEvent(QResizeEvent *event) override;
300 void showEvent(QShowEvent *event) override;
301 void closeEvent(QCloseEvent *event) override;
302 void keyPressEvent(QKeyEvent *event) override;
303 void changeEvent(QEvent *event) override;
304
305private:
306 Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
308
309 Q_DISABLE_COPY(QMessageBox)
310 Q_DECLARE_PRIVATE(QMessageBox)
311};
312
313Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons)
314
315Q_WIDGETS_EXPORT void qRequireVersion(int argc, char *argv[], QAnyStringView req);
316
317#define QT_REQUIRE_VERSION(argc, argv, str) qRequireVersion(argc, argv, str);
318
320
321#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:561
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
void closeEvent(QCloseEvent *) override
\reimp
Definition qdialog.cpp:717
void keyPressEvent(QKeyEvent *) override
\reimp
Definition qdialog.cpp:680
virtual int exec()
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition qdialog.cpp:539
void resizeEvent(QResizeEvent *) override
\reimp
Definition qdialog.cpp:1051
void showEvent(QShowEvent *) override
\reimp
Definition qdialog.cpp:850
virtual void open()
Definition qdialog.cpp:499
\inmodule QtCore
Definition qcoreevent.h:45
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QLabel widget provides a text or image display.
Definition qlabel.h:20
Definition qlist.h:74
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition qmessagebox.h:21
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:42
\inmodule QtCore
Definition qobject.h:90
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:547
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setWindowModality(Qt::WindowModality windowModality)
Definition qwidget.cpp:2806
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
void setWindowTitle(const QString &)
Definition qwidget.cpp:6109
QString text
QPushButton * button
[2]
double e
Combined button and popup list for selecting options.
WindowModality
TextFormat
@ MSWindowsFixedSizeDialogHint
Definition qnamespace.h:220
@ Dialog
Definition qnamespace.h:207
@ ButtonMask
@ Ok
Definition qbezier.cpp:275
@ Discard
Definition qbezier.cpp:276
#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
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:25
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_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
unsigned char quint8
Definition qtypes.h:41
QString title
[35]
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")
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
virtual HRESULT STDMETHODCALLTYPE Close(void)=0