Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qmessagebox.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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#include <QtWidgets/qmessagebox.h>
5
6#include <QtWidgets/qdialogbuttonbox.h>
7#include "private/qlabel_p.h"
8#include "private/qapplication_p.h"
9#include <QtCore/qlist.h>
10#include <QtCore/qdebug.h>
11#include <QtWidgets/qstyle.h>
12#include <QtWidgets/qstyleoption.h>
13#include <QtWidgets/qgridlayout.h>
14#include <QtWidgets/qpushbutton.h>
15#include <QtWidgets/qcheckbox.h>
16#include <QtGui/qaccessible.h>
17#include <QtGui/qicon.h>
18#include <QtGui/qtextdocument.h>
19#include <QtWidgets/qapplication.h>
20#if QT_CONFIG(textedit)
21#include <QtWidgets/qtextedit.h>
22#endif
23#if QT_CONFIG(menu)
24#include <QtWidgets/qmenu.h>
25#endif
26#include "qdialog_p.h"
27#include <QtGui/qfont.h>
28#include <QtGui/qfontmetrics.h>
29#include <QtGui/qclipboard.h>
30#include "private/qabstractbutton_p.h"
31#include <QtGui/qpa/qplatformtheme.h>
32
33#include <QtCore/qanystringview.h>
34#include <QtCore/qdebug.h>
35#include <QtCore/qversionnumber.h>
36
37#ifdef Q_OS_WIN
38# include <QtCore/qt_windows.h>
39#include <qpa/qplatformnativeinterface.h>
40#endif
41
42#include <optional>
43
45
46using namespace Qt::StringLiterals;
47
48#if defined(Q_OS_WIN)
49HMENU qt_getWindowsSystemMenu(const QWidget *w)
50{
52 if (void *handle = QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", window))
53 return GetSystemMenu(reinterpret_cast<HWND>(handle), false);
54 return 0;
55}
56#endif
57
58enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,
60 NewButtonMask = 0xFFFFFC00 };
61
63#if QT_CONFIG(textedit)
64class QMessageBoxDetailsText : public QWidget
65{
67public:
68 class TextEdit : public QTextEdit
69 {
70 public:
71 TextEdit(QWidget *parent=nullptr) : QTextEdit(parent) { }
72#ifndef QT_NO_CONTEXTMENU
73 void contextMenuEvent(QContextMenuEvent * e) override
74 {
75 if (QMenu *menu = createStandardContextMenu()) {
77 menu->popup(e->globalPos());
78 }
79 }
80#endif // QT_NO_CONTEXTMENU
81 };
82
83 QMessageBoxDetailsText(QWidget *parent=nullptr)
85 , copyAvailable(false)
86 {
89 QFrame *line = new QFrame(this);
90 line->setFrameShape(QFrame::HLine);
91 line->setFrameShadow(QFrame::Sunken);
93 textEdit = new TextEdit();
94 textEdit->setFixedHeight(100);
96 textEdit->setReadOnly(true);
99
100 connect(textEdit, SIGNAL(copyAvailable(bool)),
101 this, SLOT(textCopyAvailable(bool)));
102 }
103 void setText(const QString &text) { textEdit->setPlainText(text); }
104 QString text() const { return textEdit->toPlainText(); }
105
106 bool copy()
107 {
108#ifdef QT_NO_CLIPBOARD
109 return false;
110#else
111 if (!copyAvailable)
112 return false;
113 textEdit->copy();
114 return true;
115#endif
116 }
117
118 void selectAll()
119 {
120 textEdit->selectAll();
121 }
122
123private slots:
124 void textCopyAvailable(bool available)
125 {
126 copyAvailable = available;
127 }
128
129private:
130 bool copyAvailable;
132};
133#endif // QT_CONFIG(textedit)
134
136{
137public:
139 {
141 }
142
144 { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); }
145
147 { setText(label(lbl)); }
148
149 QSize sizeHint() const override
150 {
154 const QFontMetrics fm = fontMetrics();
160 ret = ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this));
161 return ret;
162 }
163};
164
166{
167 Q_DECLARE_PUBLIC(QMessageBox)
168
169public:
171#if QT_CONFIG(textedit)
172 detailsText(nullptr),
173#endif
177
178 void init(const QString &title = QString(), const QString &text = QString());
179 void setupLayout();
183
184 QAbstractButton *findButton(int button0, int button1, int button2, int flags);
185 void addOldButtons(int button0, int button1, int button2);
186
189
190 void detectEscapeButton();
191 void updateSize();
192 int layoutMinimumWidth();
193 void retranslateStrings();
194
195 void setVisible(bool visible) override;
196 bool canBeNativeDialog() const override;
197
199 const QString &title, const QString &text,
200 int button0, int button1, int button2);
202 const QString &title, const QString &text,
203 const QString &button0Text,
204 const QString &button1Text,
205 const QString &button2Text,
206 int defaultButtonNumber,
207 int escapeButtonNumber);
208
211 QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);
212
215
226#if QT_CONFIG(textedit)
227 QMessageBoxDetailsText *detailsText;
228#endif
237private:
238 void initHelper(QPlatformDialogHelper *) override;
240 int dialogCode() const override;
241};
242
244{
245 Q_Q(QMessageBox);
246
247 label = new QLabel;
248 label->setObjectName("qt_msgbox_label"_L1);
249 label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, nullptr, q)));
250 label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
251 label->setOpenExternalLinks(true);
252 iconLabel = new QLabel(q);
253 iconLabel->setObjectName("qt_msgboxex_icon_label"_L1);
255
257 buttonBox->setObjectName("qt_msgbox_buttonbox"_L1);
258 buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, nullptr, q));
261 setupLayout();
262 if (!title.isEmpty() || !text.isEmpty()) {
263 q->setWindowTitle(title);
264 q->setText(text);
265 }
266 q->setModal(true);
267#ifdef Q_OS_MAC
268 QFont f = q->font();
269 f.setBold(true);
270 label->setFont(f);
271#endif
273}
274
276{
277 Q_Q(QMessageBox);
278 delete q->layout();
279 QGridLayout *grid = new QGridLayout;
280 const bool hasIcon = !iconLabel->pixmap().isNull();
281
282 if (hasIcon)
283 grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop);
284 iconLabel->setVisible(hasIcon);
285#ifdef Q_OS_MAC
287#else
288 QSpacerItem *indentSpacer = new QSpacerItem(hasIcon ? 7 : 15, 1, QSizePolicy::Fixed, QSizePolicy::Fixed);
289#endif
290 grid->addItem(indentSpacer, 0, hasIcon ? 1 : 0, 2, 1);
291 grid->addWidget(label, 0, hasIcon ? 2 : 1, 1, 1);
292 if (informativeLabel) {
293#ifndef Q_OS_MAC
295#endif
296 grid->addWidget(informativeLabel, 1, hasIcon ? 2 : 1, 1, 1);
297 }
298 if (checkbox) {
299 grid->addWidget(checkbox, informativeLabel ? 2 : 1, hasIcon ? 2 : 1, 1, 1, Qt::AlignLeft);
300#ifdef Q_OS_MAC
301 grid->addItem(new QSpacerItem(1, 15, QSizePolicy::Fixed, QSizePolicy::Fixed), grid->rowCount(), 0);
302#else
304#endif
305 }
306#ifdef Q_OS_MAC
307 grid->addWidget(buttonBox, grid->rowCount(), hasIcon ? 2 : 1, 1, 1);
308 grid->setContentsMargins(0, 0, 0, 0);
309 grid->setVerticalSpacing(8);
310 grid->setHorizontalSpacing(0);
311 q->setContentsMargins(24, 15, 24, 20);
312 grid->setRowStretch(1, 100);
313 grid->setRowMinimumHeight(2, 6);
314#else
315 grid->addWidget(buttonBox, grid->rowCount(), 0, 1, grid->columnCount());
316#endif
317#if QT_CONFIG(textedit)
318 if (detailsText)
319 grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount());
320#endif
322 q->setLayout(grid);
323
325 updateSize();
326}
327
329{
330 layout->activate();
331 return layout->totalMinimumSize().width();
332}
333
335{
336 Q_Q(QMessageBox);
337
338 if (!q->isVisible())
339 return;
340
341 const QSize screenSize = q->screen()->availableGeometry().size();
342 int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
343 // on small screens allows the messagebox be the same size as the screen
344 if (screenSize.width() <= 1024)
345 hardLimit = screenSize.width();
346#ifdef Q_OS_MAC
347 int softLimit = qMin(screenSize.width()/2, 420);
348#else
349 // note: ideally on windows, hard and soft limits but it breaks compat
350 int softLimit = qMin(screenSize.width()/2, 500);
351#endif
352
355
356 label->setWordWrap(false); // makes the label return min size
358
359 if (width > softLimit) {
360 label->setWordWrap(true);
361 width = qMax(softLimit, layoutMinimumWidth());
362
363 if (width > hardLimit) {
364 label->d_func()->ensureTextControl();
365 if (QWidgetTextControl *control = label->d_func()->control) {
366 QTextOption opt = control->document()->defaultTextOption();
367 opt.setWrapMode(QTextOption::WrapAnywhere);
368 control->document()->setDefaultTextOption(opt);
369 }
370 width = hardLimit;
371 }
372 }
373
374 if (informativeLabel) {
380 if (width > hardLimit) { // longest word is really big, so wrap anywhere
381 informativeLabel->d_func()->ensureTextControl();
382 if (QWidgetTextControl *control = informativeLabel->d_func()->control) {
383 QTextOption opt = control->document()->defaultTextOption();
384 opt.setWrapMode(QTextOption::WrapAnywhere);
385 control->document()->setDefaultTextOption(opt);
386 }
387 width = hardLimit;
388 }
389 policy.setHeightForWidth(label->wordWrap());
390 label->setSizePolicy(policy);
391 }
392
393 QFontMetrics fm(QApplication::font("QMdiSubWindowTitleBar"));
394 int windowTitleWidth = qMin(fm.horizontalAdvance(q->windowTitle()) + 50, hardLimit);
395 if (windowTitleWidth > width)
396 width = windowTitleWidth;
397
398 layout->activate();
402
403 q->setFixedSize(width, height);
405}
406
407static int oldButton(int button)
408{
410 case QMessageBox::Ok:
411 return Old_Ok;
413 return Old_Cancel;
414 case QMessageBox::Yes:
415 return Old_Yes;
416 case QMessageBox::No:
417 return Old_No;
419 return Old_Abort;
421 return Old_Retry;
423 return Old_Ignore;
425 return Old_YesAll;
427 return Old_NoAll;
428 default:
429 return 0;
430 }
431}
432
434{
436 if (ret == QMessageBox::NoButton) {
437 ret = customButtonList.indexOf(button); // if button == 0, correctly sets ret = -1
438 } else if (compatMode) {
439 ret = oldButton(ret);
440 }
441 return ret;
442}
443
445{
446 Q_Q(const QMessageBox);
447
448 if (clickedButton) {
449 switch (q->buttonRole(clickedButton)) {
452 return QDialog::Accepted;
455 return QDialog::Rejected;
456 default:
457 ;
458 }
459 }
460
462}
463
465{
466 Q_Q(QMessageBox);
467#if QT_CONFIG(textedit)
468 if (detailsButton && detailsText && button == detailsButton) {
469 detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);
470 detailsText->setHidden(!detailsText->isHidden());
471 updateSize();
472 } else
473#endif
474 {
476
481 }
484 }
485}
486
488{
489 Q_Q(QMessageBox);
490
492 emit q->buttonClicked(clickedButton);
493
494 auto resultCode = execReturnCode(button);
495 q->done(resultCode);
496}
497
499{
500 Q_UNUSED(role);
501 Q_Q(QMessageBox);
502
503 // Map back to QAbstractButton, so that the message box behaves the same from
504 // the outside, regardless of whether it's backed by a native helper or not.
505 QAbstractButton *dialogButton = helperButton > QPlatformDialogHelper::LastButton ?
506 static_cast<QAbstractButton *>(options->customButton(helperButton)->button) :
507 q->button(QMessageBox::StandardButton(helperButton));
508
509 Q_ASSERT(dialogButton);
510
511 // Simulate click by explicitly clicking the button. This will ensure that
512 // any logic of the button that responds to the click is respected, including
513 // plumbing back to _q_buttonClicked above based on the clicked() signal.
514 dialogButton->click();
515}
516
810 : QDialog(*new QMessageBoxPrivate, parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
811{
812 Q_D(QMessageBox);
813 d->init();
814}
815
835 StandardButtons buttons, QWidget *parent,
836 Qt::WindowFlags f)
837: QDialog(*new QMessageBoxPrivate, parent, f | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
838{
839 Q_D(QMessageBox);
840 d->init(title, text);
841 setIcon(icon);
842 if (buttons != NoButton)
844}
845
850{
851}
852
862{
863 Q_D(QMessageBox);
864 if (!button)
865 return;
867
868 if (button->text().isEmpty()) {
869 if (auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
871 button->setText(platformTheme->standardButtonText(standardButton));
872 }
873
874 if (button->text().isEmpty()) {
875 qWarning() << "Cannot add" << button << "without title";
876 return;
877 }
878 }
879
880 // Add button to native dialog helper, unless it's the details button,
881 // since we don't do any plumbing for the button's action in that case.
882 if (button != d->detailsButton) {
883 d->options->addButton(button->text(),
884 static_cast<QPlatformDialogHelper::ButtonRole>(role), button);
885 }
886 d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);
887 d->customButtonList.append(button);
888 d->autoAddOkButton = false;
889}
890
892{
893 switch (role) {
902 default: return QMessageBox::NoButton;
903 }
904}
905
914{
915 Q_D(QMessageBox);
917 addButton(pushButton, role);
918 d->updateSize();
919 return pushButton;
920}
921
932{
933 Q_D(QMessageBox);
935 if (pushButton)
936 d->autoAddOkButton = false;
937 return pushButton;
938}
939
948{
949 Q_D(QMessageBox);
950 d->customButtonList.removeAll(button);
951 if (d->escapeButton == button)
952 d->escapeButton = nullptr;
953 if (d->defaultButton == button)
954 d->defaultButton = nullptr;
955 d->buttonBox->removeButton(button);
956 d->updateSize();
957}
958
970void QMessageBox::setStandardButtons(StandardButtons buttons)
971{
972 Q_D(QMessageBox);
973 d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));
974
975 QList<QAbstractButton *> buttonList = d->buttonBox->buttons();
976 if (!buttonList.contains(d->escapeButton))
977 d->escapeButton = nullptr;
978 if (!buttonList.contains(d->defaultButton))
979 d->defaultButton = nullptr;
980 d->autoAddOkButton = false;
981 d->updateSize();
982}
983
984QMessageBox::StandardButtons QMessageBox::standardButtons() const
985{
986 Q_D(const QMessageBox);
987 return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons()));
988}
989
999{
1000 Q_D(const QMessageBox);
1001 return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);
1002}
1003
1013{
1014 Q_D(const QMessageBox);
1015 return d->buttonBox->button(QDialogButtonBox::StandardButton(which));
1016}
1017
1039{
1040 Q_D(const QMessageBox);
1041 return d->escapeButton;
1042}
1043
1053{
1054 Q_D(QMessageBox);
1055 if (d->buttonBox->buttons().contains(button))
1056 d->escapeButton = button;
1057}
1058
1068{
1069 Q_D(QMessageBox);
1071}
1072
1074{
1075 if (escapeButton) { // escape button explicitly set
1077 return;
1078 }
1079
1080 // Cancel button automatically becomes escape button
1083 return;
1084
1085 // If there is only one button, make it the escape button
1086 const QList<QAbstractButton *> buttons = buttonBox->buttons();
1087 if (buttons.size() == 1) {
1088 detectedEscapeButton = buttons.first();
1089 return;
1090 }
1091
1092 // If there are two buttons and one of them is the "Show Details..."
1093 // button, then make the other one the escape button
1094 if (buttons.size() == 2 && detailsButton) {
1095 auto idx = buttons.indexOf(detailsButton);
1096 if (idx != -1) {
1097 detectedEscapeButton = buttons.at(1 - idx);
1098 return;
1099 }
1100 }
1101
1102 // if the message box has one RejectRole button, make it the escape button
1103 for (auto *button : buttons) {
1105 if (detectedEscapeButton) { // already detected!
1106 detectedEscapeButton = nullptr;
1107 break;
1108 }
1110 }
1111 }
1113 return;
1114
1115 // if the message box has one NoRole button, make it the escape button
1116 for (auto *button : buttons) {
1118 if (detectedEscapeButton) { // already detected!
1119 detectedEscapeButton = nullptr;
1120 break;
1121 }
1123 }
1124 }
1125}
1126
1143{
1144 Q_D(const QMessageBox);
1145 return d->clickedButton;
1146}
1147
1158{
1159 Q_D(const QMessageBox);
1160 return d->defaultButton;
1161}
1162
1172{
1173 Q_D(QMessageBox);
1174 if (!d->buttonBox->buttons().contains(button))
1175 return;
1176 d->defaultButton = button;
1177 button->setDefault(true);
1178 button->setFocus();
1179}
1180
1190{
1191 Q_D(QMessageBox);
1193}
1194
1204{
1205 Q_D(QMessageBox);
1206
1207 if (cb == d->checkbox)
1208 return;
1209
1210 if (d->checkbox) {
1211 d->checkbox->hide();
1212 layout()->removeWidget(d->checkbox);
1213 if (d->checkbox->parentWidget() == this) {
1214 d->checkbox->setParent(nullptr);
1215 d->checkbox->deleteLater();
1216 }
1217 }
1218 d->checkbox = cb;
1219 if (d->checkbox) {
1220 QSizePolicy sp = d->checkbox->sizePolicy();
1221 sp.setHorizontalPolicy(QSizePolicy::MinimumExpanding);
1222 d->checkbox->setSizePolicy(sp);
1223 }
1224 d->setupLayout();
1225}
1226
1227
1235{
1236 Q_D(const QMessageBox);
1237 return d->checkbox;
1238}
1239
1257{
1258 const QMessageBox::Options previousOptions = options();
1259 if (!(previousOptions & option) != !on)
1260 setOptions(previousOptions ^ option);
1261}
1262
1272{
1273 Q_D(const QMessageBox);
1274 return d->options->testOption(static_cast<QMessageDialogOptions::Option>(option));
1275}
1276
1277void QMessageBox::setOptions(QMessageBox::Options options)
1278{
1279 Q_D(QMessageBox);
1280
1282 return;
1283
1284 d->options->setOptions(QMessageDialogOptions::Option(int(options)));
1285}
1286
1287QMessageBox::Options QMessageBox::options() const
1288{
1289 Q_D(const QMessageBox);
1290 return QMessageBox::Options(int(d->options->options()));
1291}
1292
1329{
1330 Q_D(const QMessageBox);
1331 return d->label->text();
1332}
1333
1335{
1336 Q_D(QMessageBox);
1337 d->label->setText(text);
1338 d->label->setWordWrap(d->label->textFormat() == Qt::RichText
1339 || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text)));
1340 d->updateSize();
1341}
1342
1389{
1390 Q_D(const QMessageBox);
1391 return d->icon;
1392}
1393
1395{
1396 Q_D(QMessageBox);
1398 this));
1399 d->icon = icon;
1400}
1401
1415{
1416 Q_D(const QMessageBox);
1417 return d->iconLabel->pixmap();
1418}
1419
1421{
1422 Q_D(QMessageBox);
1423 d->iconLabel->setPixmap(pixmap);
1424 d->icon = NoIcon;
1425 d->setupLayout();
1426}
1427
1440{
1441 Q_D(const QMessageBox);
1442 return d->label->textFormat();
1443}
1444
1446{
1447 Q_D(QMessageBox);
1448 d->label->setTextFormat(format);
1449 d->label->setWordWrap(format == Qt::RichText
1450 || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text())));
1451 d->updateSize();
1452}
1453
1466Qt::TextInteractionFlags QMessageBox::textInteractionFlags() const
1467{
1468 Q_D(const QMessageBox);
1469 return d->label->textInteractionFlags();
1470}
1471
1472void QMessageBox::setTextInteractionFlags(Qt::TextInteractionFlags flags)
1473{
1474 Q_D(QMessageBox);
1475 d->label->setTextInteractionFlags(flags);
1476}
1477
1482{
1483 bool result =QDialog::event(e);
1484 switch (e->type()) {
1486 d_func()->updateSize();
1487 break;
1489 d_func()->retranslateStrings();
1490 break;
1491 default:
1492 break;
1493 }
1494 return result;
1495}
1496
1501{
1503}
1504
1509{
1510 Q_D(QMessageBox);
1511 if (!d->detectedEscapeButton) {
1512 e->ignore();
1513 return;
1514 }
1516 if (!d->clickedButton) {
1517 d->clickedButton = d->detectedEscapeButton;
1518 setResult(d->execReturnCode(d->detectedEscapeButton));
1519 }
1520}
1521
1526{
1527 Q_D(QMessageBox);
1528 switch (ev->type()) {
1530 {
1531 if (d->icon != NoIcon)
1532 setIcon(d->icon);
1533 Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, nullptr, this));
1534 d->label->setTextInteractionFlags(flags);
1535 d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, nullptr, this));
1536 if (d->informativeLabel)
1537 d->informativeLabel->setTextInteractionFlags(flags);
1538 Q_FALLTHROUGH();
1539 }
1540 case QEvent::FontChange:
1542#ifdef Q_OS_MAC
1543 {
1544 QFont f = font();
1545 f.setBold(true);
1546 d->label->setFont(f);
1547 }
1548#endif
1549 Q_FALLTHROUGH();
1550 default:
1551 break;
1552 }
1554}
1555
1560{
1561#if QT_CONFIG(shortcut)
1562 Q_D(QMessageBox);
1563 if (e->matches(QKeySequence::Cancel)) {
1564 if (d->detectedEscapeButton) {
1565#ifdef Q_OS_MAC
1566 d->detectedEscapeButton->animateClick();
1567#else
1568 d->detectedEscapeButton->click();
1569#endif
1570 }
1571 return;
1572 }
1573#endif // QT_CONFIG(shortcut)
1574
1575#if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
1576
1577#if QT_CONFIG(textedit)
1578 if (e == QKeySequence::Copy) {
1579 if (d->detailsText && d->detailsText->isVisible() && d->detailsText->copy()) {
1580 e->setAccepted(true);
1581 return;
1582 }
1583 } else if (e == QKeySequence::SelectAll && d->detailsText && d->detailsText->isVisible()) {
1584 d->detailsText->selectAll();
1585 e->setAccepted(true);
1586 return;
1587 }
1588#endif // QT_CONFIG(textedit)
1589
1590#if defined(Q_OS_WIN)
1591 if (e == QKeySequence::Copy) {
1592 const auto separator = "---------------------------\n"_L1;
1593 QString textToCopy;
1594 textToCopy += separator + windowTitle() + u'\n' + separator // title
1595 + d->label->text() + u'\n' + separator; // text
1596
1597 if (d->informativeLabel)
1598 textToCopy += d->informativeLabel->text() + u'\n' + separator;
1599
1600 const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
1601 for (const auto *button : buttons)
1602 textToCopy += button->text() + " "_L1;
1603 textToCopy += u'\n' + separator;
1604#if QT_CONFIG(textedit)
1605 if (d->detailsText)
1606 textToCopy += d->detailsText->text() + u'\n' + separator;
1607#endif
1608 QGuiApplication::clipboard()->setText(textToCopy);
1609 return;
1610 }
1611#endif // Q_OS_WIN
1612
1613#endif // !QT_NO_CLIPBOARD && !QT_NO_SHORTCUT
1614
1615#ifndef QT_NO_SHORTCUT
1616 if (!(e->modifiers() & (Qt::AltModifier | Qt::ControlModifier | Qt::MetaModifier))) {
1617 int key = e->key() & ~Qt::MODIFIER_MASK;
1618 if (key) {
1619 const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
1620 for (auto *pb : buttons) {
1621 QKeySequence shortcut = pb->shortcut();
1622 if (!shortcut.isEmpty() && key == shortcut[0].key()) {
1623 pb->animateClick();
1624 return;
1625 }
1626 }
1627 }
1628 }
1629#endif
1631}
1632
1641void QMessageBox::open(QObject *receiver, const char *member)
1642{
1643 Q_D(QMessageBox);
1644 const char *signal = member && strchr(member, '*') ? SIGNAL(buttonClicked(QAbstractButton*))
1645 : SIGNAL(finished(int));
1646 connect(this, signal, receiver, member);
1647 d->signalToDisconnectOnClose = signal;
1648 d->receiverToDisconnectOnClose = receiver;
1649 d->memberToDisconnectOnClose = member;
1650 QDialog::open();
1651}
1652
1654{
1655 Q_Q(QMessageBox);
1656 if (q->testAttribute(Qt::WA_WState_ExplicitShowHide) && q->testAttribute(Qt::WA_WState_Hidden) != visible)
1657 return;
1658
1659 if (canBeNativeDialog())
1660 setNativeDialogVisible(visible);
1661
1662 // Update WA_DontShowOnScreen based on whether the native dialog was shown,
1663 // so that QDialog::setVisible(visible) below updates the QWidget state correctly,
1664 // but skips showing the non-native version.
1666
1668}
1669
1678{
1679 Q_D(const QMessageBox);
1680 return d->buttonBox->buttons();
1681}
1682
1692{
1693 Q_D(const QMessageBox);
1694 return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button));
1695}
1696
1701{
1702 Q_D(QMessageBox);
1703 if (d->autoAddOkButton) {
1704 addButton(Ok);
1705 }
1706 if (d->detailsButton)
1707 addButton(d->detailsButton, QMessageBox::ActionRole);
1708 d->clickedButton = nullptr;
1709 d->detectEscapeButton();
1710 d->updateSize();
1711
1712#if QT_CONFIG(accessibility)
1713 QAccessibleEvent event(this, QAccessible::Alert);
1714 QAccessible::updateAccessibility(&event);
1715#endif
1716#if defined(Q_OS_WIN)
1717 if (const HMENU systemMenu = qt_getWindowsSystemMenu(this)) {
1718 EnableMenuItem(systemMenu, SC_CLOSE, d->detectedEscapeButton ?
1719 MF_BYCOMMAND|MF_ENABLED : MF_BYCOMMAND|MF_GRAYED);
1720 }
1721#endif
1723}
1724
1725
1728 const QString& title, const QString& text,
1729 QMessageBox::StandardButtons buttons,
1730 QMessageBox::StandardButton defaultButton)
1731{
1732 // necessary for source compatibility with Qt 4.0 and 4.1
1733 // handles (Yes, No) and (Yes|Default, No)
1734 if (defaultButton && !(buttons & defaultButton))
1737 text, int(buttons),
1738 int(defaultButton), 0);
1739
1742 Q_ASSERT(buttonBox != nullptr);
1743
1745 while (mask <= QMessageBox::LastButton) {
1746 uint sb = buttons & mask;
1747 mask <<= 1;
1748 if (!sb)
1749 continue;
1751 // Choose the first accept role as the default
1752 if (msgBox.defaultButton())
1753 continue;
1754 if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
1755 || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton)))
1757 }
1758 if (msgBox.exec() == -1)
1759 return QMessageBox::Cancel;
1761}
1762
1789 const QString& text, StandardButtons buttons,
1790 StandardButton defaultButton)
1791{
1794}
1795
1796
1823 const QString& text, StandardButtons buttons,
1824 StandardButton defaultButton)
1825{
1827}
1828
1855 const QString& text, StandardButtons buttons,
1856 StandardButton defaultButton)
1857{
1859}
1860
1887 const QString& text, StandardButtons buttons,
1888 StandardButton defaultButton)
1889{
1891}
1892
1914{
1915#ifdef Q_OS_MAC
1916 static QPointer<QMessageBox> oldMsgBox;
1917
1918 if (oldMsgBox && oldMsgBox->text() == text) {
1919 oldMsgBox->show();
1920 oldMsgBox->raise();
1921 oldMsgBox->activateWindow();
1922 return;
1923 }
1924#endif
1925
1927#ifdef Q_OS_MAC
1929#endif
1930 );
1933 QSize size = icon.actualSize(QSize(64, 64));
1934 msgBox->setIconPixmap(icon.pixmap(size));
1935
1936 // should perhaps be a style hint
1937#ifdef Q_OS_MAC
1938 oldMsgBox = msgBox;
1939#if 0
1940 // ### doesn't work until close button is enabled in title bar
1941 msgBox->d_func()->autoAddOkButton = false;
1942#else
1943 msgBox->d_func()->buttonBox->setCenterButtons(true);
1944#endif
1945 msgBox->setModal(false);
1946 msgBox->show();
1947#else
1948 msgBox->exec();
1949#endif
1950}
1951
1968{
1969#ifdef Q_OS_MAC
1970 static QPointer<QMessageBox> oldMsgBox;
1971
1972 if (oldMsgBox) {
1973 oldMsgBox->show();
1974 oldMsgBox->raise();
1975 oldMsgBox->activateWindow();
1976 return;
1977 }
1978#endif
1979
1980 QString translatedTextAboutQtCaption;
1981 translatedTextAboutQtCaption = QMessageBox::tr(
1982 "<h3>About Qt</h3>"
1983 "<p>This program uses Qt version %1.</p>"
1984 ).arg(QT_VERSION_STR ""_L1);
1985 //: Leave this text untranslated or include a verbatim copy of it below
1986 //: and note that it is the authoritative version in case of doubt.
1987 const QString translatedTextAboutQtText = QMessageBox::tr(
1988 "<p>Qt is a C++ toolkit for cross-platform application "
1989 "development.</p>"
1990 "<p>Qt provides single-source portability across all major desktop "
1991 "operating systems. It is also available for embedded Linux and other "
1992 "embedded and mobile operating systems.</p>"
1993 "<p>Qt is available under multiple licensing options designed "
1994 "to accommodate the needs of our various users.</p>"
1995 "<p>Qt licensed under our commercial license agreement is appropriate "
1996 "for development of proprietary/commercial software where you do not "
1997 "want to share any source code with third parties or otherwise cannot "
1998 "comply with the terms of GNU (L)GPL.</p>"
1999 "<p>Qt licensed under GNU (L)GPL is appropriate for the "
2000 "development of Qt&nbsp;applications provided you can comply with the terms "
2001 "and conditions of the respective licenses.</p>"
2002 "<p>Please see <a href=\"http://%2/\">%2</a> "
2003 "for an overview of Qt licensing.</p>"
2004 "<p>Copyright (C) %1 The Qt Company Ltd and other "
2005 "contributors.</p>"
2006 "<p>Qt and the Qt logo are trademarks of The Qt Company Ltd.</p>"
2007 "<p>Qt is The Qt Company Ltd product developed as an open source "
2008 "project. See <a href=\"http://%3/\">%3</a> for more information.</p>"
2009 ).arg(QLatin1String(QT_COPYRIGHT_YEAR),
2010 QStringLiteral("qt.io/licensing"),
2011 QStringLiteral("qt.io"));
2014 msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title);
2015 msgBox->setText(translatedTextAboutQtCaption);
2016 msgBox->setInformativeText(translatedTextAboutQtText);
2017
2018 QPixmap pm(":/qt-project.org/qmessagebox/images/qtlogo-64.png"_L1);
2019 if (!pm.isNull())
2020 msgBox->setIconPixmap(pm);
2021
2022 // should perhaps be a style hint
2023#ifdef Q_OS_MAC
2024 oldMsgBox = msgBox;
2025#if 0
2026 // ### doesn't work until close button is enabled in title bar
2027 msgBox->d_func()->autoAddOkButton = false;
2028#else
2029 msgBox->d_func()->buttonBox->setCenterButtons(true);
2030#endif
2031 msgBox->setModal(false);
2032 msgBox->show();
2033#else
2034 msgBox->exec();
2035#endif
2036}
2037
2039// Source and binary compatibility routines for 4.0 and 4.1
2040
2042{
2043 // this is needed for source compatibility with Qt 4.0 and 4.1
2046
2047 return QMessageBox::NoButton;
2048}
2049
2050static bool detectedCompat(int button0, int button1, int button2)
2051{
2052 if (button0 != 0 && !(button0 & NewButtonMask))
2053 return true;
2054 if (button1 != 0 && !(button1 & NewButtonMask))
2055 return true;
2056 if (button2 != 0 && !(button2 & NewButtonMask))
2057 return true;
2058 return false;
2059}
2060
2061QAbstractButton *QMessageBoxPrivate::findButton(int button0, int button1, int button2, int flags)
2062{
2063 Q_Q(QMessageBox);
2064 int button = 0;
2065
2066 if (button0 & flags) {
2067 button = button0;
2068 } else if (button1 & flags) {
2069 button = button1;
2070 } else if (button2 & flags) {
2071 button = button2;
2072 }
2073 return q->button(newButton(button));
2074}
2075
2076void QMessageBoxPrivate::addOldButtons(int button0, int button1, int button2)
2077{
2078 Q_Q(QMessageBox);
2079 q->addButton(newButton(button0));
2080 q->addButton(newButton(button1));
2081 q->addButton(newButton(button2));
2082 q->setDefaultButton(
2083 static_cast<QPushButton *>(findButton(button0, button1, button2, QMessageBox::Default)));
2084 q->setEscapeButton(findButton(button0, button1, button2, QMessageBox::Escape));
2085 compatMode = detectedCompat(button0, button1, button2);
2086}
2087
2089{
2090 Q_Q(const QMessageBox);
2092 if (result)
2093 return result;
2094 if (id & QMessageBox::FlagMask) // for compatibility with Qt 4.0/4.1 (even if it is silly)
2095 return nullptr;
2096 return q->button(newButton(id));
2097}
2098
2100 const QString &title, const QString &text,
2101 int button0, int button1, int button2)
2102{
2104 messageBox.d_func()->addOldButtons(button0, button1, button2);
2105 return messageBox.exec();
2106}
2107
2109 const QString &title, const QString &text,
2110 const QString &button0Text,
2111 const QString &button1Text,
2112 const QString &button2Text,
2113 int defaultButtonNumber,
2114 int escapeButtonNumber)
2115{
2117 QString myButton0Text = button0Text;
2118 if (myButton0Text.isEmpty())
2119 myButton0Text = QDialogButtonBox::tr("OK");
2121 if (!button1Text.isEmpty())
2123 if (!button2Text.isEmpty())
2125
2126 const QList<QAbstractButton *> &buttonList = messageBox.d_func()->customButtonList;
2127 messageBox.setDefaultButton(static_cast<QPushButton *>(buttonList.value(defaultButtonNumber)));
2128 messageBox.setEscapeButton(buttonList.value(escapeButtonNumber));
2129
2130 return messageBox.exec();
2131}
2132
2134{
2135#if QT_CONFIG(textedit)
2136 if (detailsButton && detailsText)
2137 detailsButton->setLabel(detailsText->isHidden() ? ShowLabel : HideLabel);
2138#endif
2139}
2140
2141#if QT_DEPRECATED_SINCE(6,2)
2195 int button0, int button1, int button2, QWidget *parent,
2196 Qt::WindowFlags f)
2198 f /*| Qt::MSWindowsFixedSizeDialogHint #### */| Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
2199{
2200 Q_D(QMessageBox);
2201 d->init(title, text);
2202 setIcon(icon);
2203 d->addOldButtons(button0, button1, button2);
2204}
2205
2246 int button0, int button1, int button2)
2247{
2249 button0, button1, button2);
2250}
2251
2283 const QString& button0Text, const QString& button1Text,
2284 const QString& button2Text, int defaultButtonNumber,
2285 int escapeButtonNumber)
2286{
2288 button0Text, button1Text, button2Text,
2289 defaultButtonNumber, escapeButtonNumber);
2290}
2291
2333 int button0, int button1, int button2)
2334{
2336 button0, button1, button2);
2337}
2338
2369 const QString& button0Text, const QString& button1Text,
2370 const QString& button2Text, int defaultButtonNumber,
2371 int escapeButtonNumber)
2372{
2374 button0Text, button1Text, button2Text,
2375 defaultButtonNumber, escapeButtonNumber);
2376}
2377
2378
2419 int button0, int button1, int button2)
2420{
2422 button0, button1, button2);
2423}
2424
2455 const QString& button0Text, const QString& button1Text,
2456 const QString& button2Text, int defaultButtonNumber,
2457 int escapeButtonNumber)
2458{
2460 button0Text, button1Text, button2Text,
2461 defaultButtonNumber, escapeButtonNumber);
2462}
2463
2505 int button0, int button1, int button2)
2506{
2508 button0, button1, button2);
2509}
2510
2541 const QString& button0Text, const QString& button1Text,
2542 const QString& button2Text, int defaultButtonNumber,
2543 int escapeButtonNumber)
2544{
2546 button0Text, button1Text, button2Text,
2547 defaultButtonNumber, escapeButtonNumber);
2548}
2549
2550
2559QString QMessageBox::buttonText(int button) const
2560{
2561 Q_D(const QMessageBox);
2562
2563 if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
2564 return abstractButton->text();
2565 } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
2566 // for compatibility with Qt 4.0/4.1
2567 return QDialogButtonBox::tr("OK");
2568 }
2569 return QString();
2570}
2571
2581void QMessageBox::setButtonText(int button, const QString &text)
2582{
2583 Q_D(QMessageBox);
2584 if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
2585 abstractButton->setText(text);
2586 } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
2587 // for compatibility with Qt 4.0/4.1
2588 addButton(QMessageBox::Ok)->setText(text);
2589 }
2590}
2591#endif // QT_DEPRECATED_SINCE(6,2)
2592
2593
2594#if QT_CONFIG(textedit)
2606QString QMessageBox::detailedText() const
2607{
2608 Q_D(const QMessageBox);
2609 return d->detailsText ? d->detailsText->text() : QString();
2610}
2611
2612void QMessageBox::setDetailedText(const QString &text)
2613{
2614 Q_D(QMessageBox);
2615 if (text.isEmpty()) {
2616 if (d->detailsText) {
2617 d->detailsText->hide();
2618 d->detailsText->deleteLater();
2619 }
2620 d->detailsText = nullptr;
2621 removeButton(d->detailsButton);
2622 if (d->detailsButton) {
2623 d->detailsButton->hide();
2624 d->detailsButton->deleteLater();
2625 }
2626 d->detailsButton = nullptr;
2627 } else {
2628 if (!d->detailsText) {
2629 d->detailsText = new QMessageBoxDetailsText(this);
2630 d->detailsText->hide();
2631 }
2632 if (!d->detailsButton) {
2633 const bool autoAddOkButton = d->autoAddOkButton; // QTBUG-39334, addButton() clears the flag.
2634 d->detailsButton = new DetailButton(this);
2635 addButton(d->detailsButton, QMessageBox::ActionRole);
2636 d->autoAddOkButton = autoAddOkButton;
2637 }
2638 d->detailsText->setText(text);
2639 }
2640 d->setupLayout();
2641}
2642#endif // QT_CONFIG(textedit)
2643
2661{
2662 Q_D(const QMessageBox);
2663 return d->informativeLabel ? d->informativeLabel->text() : QString();
2664}
2665
2667{
2668 Q_D(QMessageBox);
2669 if (text.isEmpty()) {
2670 if (d->informativeLabel) {
2671 d->informativeLabel->hide();
2672 d->informativeLabel->deleteLater();
2673 }
2674 d->informativeLabel = nullptr;
2675 } else {
2676 if (!d->informativeLabel) {
2677 QLabel *label = new QLabel;
2678 label->setObjectName("qt_msgbox_informativelabel"_L1);
2679 label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, nullptr, this)));
2680 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
2681 label->setOpenExternalLinks(true);
2682 label->setWordWrap(true);
2683#ifdef Q_OS_MAC
2684 // apply a smaller font the information label on the mac
2685 label->setFont(qt_app_fonts_hash()->value("QTipLabel"));
2686#endif
2687 label->setWordWrap(true);
2688 d->informativeLabel = label;
2689 }
2690 d->informativeLabel->setText(text);
2691 }
2692 d->setupLayout();
2693}
2694
2705{
2706 // Message boxes on the mac do not have a title
2707#ifndef Q_OS_MAC
2709#else
2710 Q_UNUSED(title);
2711#endif
2712}
2713
2714
2727{
2729
2732 else
2735}
2736
2737
2739{
2740 QStyle *style = mb ? mb->style() : QApplication::style();
2741 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, mb);
2742 QIcon tmpIcon;
2743 switch (icon) {
2745 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, mb);
2746 break;
2748 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, mb);
2749 break;
2751 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, nullptr, mb);
2752 break;
2754 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, nullptr, mb);
2755 default:
2756 break;
2757 }
2758 if (!tmpIcon.isNull()) {
2759 qreal dpr = mb ? mb->devicePixelRatio() : qApp->devicePixelRatio();
2760 return tmpIcon.pixmap(QSize(iconSize, iconSize), dpr);
2761 }
2762 return QPixmap();
2763}
2764
2766{
2767 Q_Q(QMessageBox);
2770
2771 auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(h);
2773 [this](Qt::CheckState state) {
2774 if (checkbox)
2776 }
2777 );
2778
2779 static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options);
2780}
2781
2783{
2784 switch (i) {
2795 }
2797}
2798
2799static QPlatformDialogHelper::StandardButtons helperStandardButtons(QMessageBox * q)
2800{
2801 QPlatformDialogHelper::StandardButtons buttons(int(q->standardButtons()));
2802 return buttons;
2803}
2804
2806{
2807 // Don't use Q_Q here! This function is called from ~QDialog,
2808 // so Q_Q calling q_func() invokes undefined behavior (invalid cast in q_func()).
2809 const QDialog * const q = static_cast<const QMessageBox*>(q_ptr);
2811 return true;
2813 || q->testAttribute(Qt::WA_DontShowOnScreen)
2815 return false;
2816 }
2817
2818 if (strcmp(QMessageBox::staticMetaObject.className(), q->metaObject()->className()) != 0)
2819 return false;
2820
2822}
2823
2825{
2826 Q_Q(QMessageBox);
2827 options->setWindowTitle(q->windowTitle());
2828 options->setText(q->text());
2829 options->setInformativeText(q->informativeText());
2830#if QT_CONFIG(textedit)
2831 options->setDetailedText(q->detailedText());
2832#endif
2834 options->setIconPixmap(q->iconPixmap());
2836 if (checkbox)
2838}
2839
2840void qRequireVersion(int argc, char *argv[], QAnyStringView req)
2841{
2842 const auto required = QVersionNumber::fromString(req).normalized();
2843 const auto current = QVersionNumber::fromString(qVersion()).normalized();
2844 if (current >= required)
2845 return;
2846 std::optional<QApplication> application;
2847 if (!qApp)
2848 application.emplace(argc, argv);
2849 const QString message = QApplication::tr("Application \"%1\" requires Qt %2, found Qt %3.")
2850 .arg(qAppName(), required.toString(), current.toString());
2851 QMessageBox::critical(nullptr, QApplication::tr("Incompatible Qt Library Error"),
2854}
2855
2856#if QT_DEPRECATED_SINCE(6,2)
2870QPixmap QMessageBox::standardIcon(Icon icon)
2871{
2872 return QMessageBoxPrivate::standardIcon(icon, nullptr);
2873}
2874#endif
2875
2942
2943#include "moc_qmessagebox.cpp"
2944#include "qmessagebox.moc"
DetailButton(QWidget *parent)
QString label(DetailButtonLabel label) const
void setLabel(DetailButtonLabel lbl)
QSize sizeHint() const override
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
void click()
Performs a click.
void setText(const QString &text)
QString text
the text shown on the button
\inmodule QtCore
static QWindow * windowForWidget(const QWidget *widget)
static QStyle * style()
Returns the application's style object.
static QFont font()
Returns the default application font.
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
\inmodule QtCore
Definition qbytearray.h:57
void clear()
Clears the contents of the byte array and makes it null.
The QCheckBox widget provides a checkbox with a text label.
Definition qcheckbox.h:19
void setCheckState(Qt::CheckState state)
Sets the checkbox's check state to state.
Qt::CheckState checkState() const
Returns the checkbox's check state.
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:561
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
static void removePostedEvents(QObject *receiver, int eventType=0)
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
ButtonRole buttonRole(QAbstractButton *button) const
Returns the button role for the specified button.
StandardButton
These enums describe flags for standard buttons.
QPushButton * button(StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or \nullptr if the standard butto...
StandardButton standardButton(QAbstractButton *button) const
Returns the standard button enum value corresponding to the given button, or NoButton if the given bu...
void setCenterButtons(bool center)
QList< QAbstractButton * > buttons() const
Returns a list of all buttons that have been added to the button box.
bool setNativeDialogVisible(bool visible)
Definition qdialog.cpp:162
virtual void setVisible(bool visible)
Definition qdialog.cpp:746
virtual bool canBeNativeDialog() const
Definition qdialog.cpp:99
bool nativeDialogInUse
Definition qdialog_p.h:86
virtual int dialogCode() const
Definition qdialog_p.h:93
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
void closeEvent(QCloseEvent *) override
\reimp
Definition qdialog.cpp:717
void finished(int result)
void setResult(int r)
Sets the modal dialog's result code to i.
Definition qdialog.cpp:485
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
int result() const
In general returns the modal dialog's result code, Accepted or Rejected.
Definition qdialog.cpp:471
@ Accepted
Definition qdialog.h:30
@ Rejected
Definition qdialog.h:30
void setModal(bool modal)
Definition qdialog.cpp:1001
void resizeEvent(QResizeEvent *) override
\reimp
Definition qdialog.cpp:1051
void showEvent(QShowEvent *) override
\reimp
Definition qdialog.cpp:850
friend class QPushButton
[1]
Definition qdialog.h:21
virtual void open()
Definition qdialog.cpp:499
\inmodule QtCore
Definition qcoreevent.h:45
@ StyleChange
Definition qcoreevent.h:136
@ LayoutRequest
Definition qcoreevent.h:112
@ FontChange
Definition qcoreevent.h:133
@ LanguageChange
Definition qcoreevent.h:123
@ ApplicationFontChange
Definition qcoreevent.h:91
Type type() const
Returns the event type.
Definition qcoreevent.h:299
\reentrant \inmodule QtGui
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=nullptr) const
Returns the size in pixels of text.
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
\reentrant
Definition qfont.h:20
void setBold(bool)
If enable is true sets the font's weight to \l{Weight}{QFont::Bold}; otherwise sets the weight to \l{...
Definition qfont.h:312
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
@ Sunken
Definition qframe.h:51
@ HLine
Definition qframe.h:43
void setFocusPolicy(Qt::FocusPolicy policy)
The QGridLayout class lays out widgets in a grid.
Definition qgridlayout.h:21
void setHorizontalSpacing(int spacing)
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qgridlayout.h:64
void setRowMinimumHeight(int row, int minSize)
Sets the minimum height of row row to minSize pixels.
int rowCount() const
Returns the number of rows in this grid.
void addItem(QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=Qt::Alignment())
Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it accord...
void setVerticalSpacing(int spacing)
void setRowStretch(int row, int stretch)
Sets the stretch factor of row row to stretch.
int columnCount() const
Returns the number of columns in this grid.
static QPlatformTheme * platformTheme()
static QPlatformNativeInterface * platformNativeInterface()
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:973
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition qicon.cpp:788
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QKeySequence class encapsulates a key sequence as used by shortcuts.
The QLabel widget provides a text or image display.
Definition qlabel.h:20
QPixmap pixmap
the label's pixmap.
Definition qlabel.h:24
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
int totalHeightForWidth(int w) const
Definition qlayout.cpp:598
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition qlayout.cpp:1322
void setSizeConstraint(SizeConstraint)
Definition qlayout.cpp:1240
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:994
QSize totalMinimumSize() const
Definition qlayout.cpp:620
@ SetNoConstraint
Definition qlayout.h:37
void setContentsMargins(int left, int top, int right, int bottom)
Definition qlayout.cpp:288
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
T & first()
Definition qlist.h:628
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
T value(qsizetype i) const
Definition qlist.h:661
\inmodule QtCore
Definition qmargins.h:23
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
void popup(const QPoint &pos, QAction *at=nullptr)
Displays the menu so that the action atAction will be at the specified global position p.
Definition qmenu.cpp:2288
QDialogButtonBox * buttonBox
QAbstractButton * abstractButtonForId(int id) const
QList< QAbstractButton * > customButtonList
void initHelper(QPlatformDialogHelper *) override
DetailButton * detailsButton
void _q_buttonClicked(QAbstractButton *)
int execReturnCode(QAbstractButton *button)
QMessageBox::Icon icon
bool canBeNativeDialog() const override
void addOldButtons(int button0, int button1, int button2)
static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
void init(const QString &title=QString(), const QString &text=QString())
QAbstractButton * clickedButton
QPushButton * defaultButton
int dialogCode() const override
QSharedPointer< QMessageDialogOptions > options
void setVisible(bool visible) override
QAbstractButton * escapeButton
QPointer< QObject > receiverToDisconnectOnClose
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)
QByteArray memberToDisconnectOnClose
void helperPrepareShow(QPlatformDialogHelper *) override
QAbstractButton * findButton(int button0, int button1, int button2, int flags)
void setClickedButton(QAbstractButton *button)
static QMessageBox::StandardButton standardButtonForRole(QMessageBox::ButtonRole role)
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QAbstractButton * detectedEscapeButton
void _q_helperClicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
QByteArray signalToDisconnectOnClose
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition qmessagebox.h:21
QList< QAbstractButton * > buttons() const
void closeEvent(QCloseEvent *event) override
\reimp
void changeEvent(QEvent *event) override
\reimp
void setEscapeButton(QAbstractButton *button)
bool testOption(Option option) const
void setStandardButtons(StandardButtons buttons)
void setWindowTitle(const QString &title)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void buttonClicked(QAbstractButton *button)
This signal is emitted whenever a button is clicked inside the QMessageBox.
Qt::TextFormat textFormat
the format of the text displayed by the message box
Definition qmessagebox.h:26
void setIcon(Icon)
StandardButtons standardButtons
collection of standard buttons in the message box
Definition qmessagebox.h:27
void keyPressEvent(QKeyEvent *event) override
\reimp
QMessageBox(QWidget *parent=nullptr)
Constructs an \l{Qt::ApplicationModal} {application modal} message box with no text and no buttons.
~QMessageBox()
Destroys the message box.
void addButton(QAbstractButton *button, ButtonRole role)
bool event(QEvent *e) override
\reimp
void removeButton(QAbstractButton *button)
void setInformativeText(const QString &text)
static void aboutQt(QWidget *parent, const QString &title=QString())
Displays a simple message box about Qt, with the given title and centered over parent (if parent is n...
void resizeEvent(QResizeEvent *event) override
\reimp
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setOptions(Options options)
void setTextFormat(Qt::TextFormat format)
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void showEvent(QShowEvent *event) override
\reimp
static void about(QWidget *parent, const QString &title, const QString &text)
Displays a simple about box with title title and text text.
QString text
the message box text to be displayed.
Definition qmessagebox.h:23
Icon icon
the message box's icon
Definition qmessagebox.h:24
QPushButton * defaultButton() const
Options options
options that affect the look and feel of the dialog
Definition qmessagebox.h:34
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
void setWindowModality(Qt::WindowModality windowModality)
QAbstractButton * clickedButton() const
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=StandardButtons(Yes|No), StandardButton defaultButton=NoButton)
Icon
This enum has the following values:
Definition qmessagebox.h:42
void setIconPixmap(const QPixmap &pixmap)
Qt::TextInteractionFlags textInteractionFlags
Definition qmessagebox.h:33
void setCheckBox(QCheckBox *cb)
StandardButton standardButton(QAbstractButton *button) const
void setOption(Option option, bool on=true)
QPixmap iconPixmap
the current icon
Definition qmessagebox.h:25
virtual void open()
Definition qdialog.cpp:499
QAbstractButton * escapeButton() const
ButtonRole buttonRole(QAbstractButton *button) const
void setText(const QString &text)
void setDefaultButton(QPushButton *button)
QString informativeText
the informative text that provides a fuller description for the message
Definition qmessagebox.h:31
QAbstractButton * button(StandardButton which) const
QCheckBox * checkBox() const
void setWindowTitle(const QString &)
void setInformativeText(const QString &text)
void setDetailedText(const QString &text)
void setText(const QString &text)
void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons)
const CustomButton * customButton(int id)
void setCheckBox(const QString &label, Qt::CheckState state)
void setStandardIcon(StandardIcon icon)
void setIconPixmap(const QPixmap &pixmap)
QObject * q_ptr
Definition qobject.h:60
QObject * parent
Definition qobject.h:61
\inmodule QtCore
Definition qobject.h:90
T findChild(const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
Definition qobject.h:133
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1363
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3099
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:114
qreal devicePixelRatio() const
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition qpixmap.cpp:460
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
The QPlatformMessageDialogHelper class allows for platform-specific customization of Message dialogs.
void checkBoxStateChanged(Qt::CheckState state)
\inmodule QtCore
Definition qpointer.h:18
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
void setDefault(bool)
virtual void initStyleOption(QStyleOptionButton *option) const
Initialize option with the values from this QPushButton.
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
\inmodule QtCore
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
constexpr void setHeightForWidth(bool b) noexcept
Sets the flag determining whether the widget's preferred height depends on its width,...
Definition qsizepolicy.h:80
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
The QSpacerItem class provides blank space in a layout.
Definition qlayoutitem.h:57
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8606
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
\variable QStyleOptionHeaderV2::textElideMode
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ CT_PushButton
Definition qstyle.h:545
virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_MessageBox_CenterButtons
Definition qstyle.h:655
@ SH_MessageBox_TextInteractionFlags
Definition qstyle.h:653
@ SP_MessageBoxQuestion
Definition qstyle.h:727
@ SP_MessageBoxCritical
Definition qstyle.h:726
@ SP_MessageBoxInformation
Definition qstyle.h:724
@ SP_MessageBoxWarning
Definition qstyle.h:725
@ PM_MessageBoxIconSize
Definition qstyle.h:504
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
\reentrant
Definition qtextoption.h:18
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
static Q_CORE_EXPORT QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex=nullptr)
Q_CORE_EXPORT QVersionNumber normalized() const
Returns an equivalent version number but with all trailing zeros removed.
QLayout * layout
Definition qwidget_p.h:643
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void setWindowModality(Qt::WindowModality windowModality)
Definition qwidget.cpp:2806
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right,...
Definition qwidget.cpp:7676
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Qt::WindowModality windowModality
which windows are blocked by the modal widget
Definition qwidget.h:104
void setSizePolicy(QSizePolicy)
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7956
virtual void setVisible(bool visible)
Definition qwidget.cpp:8329
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
QIcon windowIcon
the widget's icon
Definition qwidget.h:152
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
QStyle * style() const
Definition qwidget.cpp:2607
QFont font
the font currently set for the widget
Definition qwidget.h:133
QString windowTitle
the window title (caption)
Definition qwidget.h:151
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
\inmodule QtGui
Definition qwindow.h:63
QString text
QPushButton * button
[2]
double e
auto signal
opt iconSize
QStyleOptionButton opt
else opt state
[0]
Combined button and popup list for selecting options.
CheckState
@ AlignVCenter
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:152
@ AlignLeft
Definition qnamespace.h:143
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:334
@ WA_DontShowOnScreen
Definition qnamespace.h:382
@ WA_WState_Hidden
Definition qnamespace.h:296
@ WA_DeleteOnClose
Definition qnamespace.h:320
WindowModality
@ WindowModal
TextFormat
@ RichText
@ AutoText
@ NoFocus
Definition qnamespace.h:106
@ TextShowMnemonic
Definition qnamespace.h:172
@ ControlModifier
@ MetaModifier
@ AltModifier
@ AA_DontUseNativeDialogs
Definition qnamespace.h:457
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
@ Dialog
Definition qnamespace.h:207
@ Sheet
Definition qnamespace.h:208
@ WindowTitleHint
Definition qnamespace.h:225
@ WindowSystemMenuHint
Definition qnamespace.h:226
static jboolean copy(JNIEnv *, jobject)
static jboolean selectAll(JNIEnv *, jobject)
FontHash * qt_app_fonts_hash()
#define Q_FALLTHROUGH()
QString qAppName()
#define qApp
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:162
#define qFatal
Definition qlogging.h:164
return ret
Button
@ Old_No
@ Old_NoAll
@ Old_YesAll
@ Old_Ignore
@ Old_Retry
@ Old_Abort
@ Old_ButtonMask
@ Old_Yes
@ Old_Ok
@ NewButtonMask
@ Old_Cancel
static int oldButton(int button)
static QMessageDialogOptions::StandardIcon helperIcon(QMessageBox::Icon i)
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
static QMessageBox::StandardButton newButton(int button)
static bool detectedCompat(int button0, int button1, int button2)
void qRequireVersion(int argc, char *argv[], QAnyStringView req)
DetailButtonLabel
@ ShowLabel
@ HideLabel
static QPlatformDialogHelper::StandardButtons helperStandardButtons(QMessageBox *q)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLuint64 GLenum void * handle
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLint GLsizei width
GLuint GLsizei const GLchar * label
[43]
GLbitfield flags
GLuint GLsizei const GLchar * message
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLuint GLenum option
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define qUtf16Printable(string)
Definition qstring.h:1403
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define sp
#define QT_CONFIG(feature)
#define tr(X)
#define Q_OBJECT
#define slots
#define emit
#define Q_UNUSED(x)
QT_BEGIN_NAMESPACE Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char * qVersion(void) Q_DECL_NOEXCEPT
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
const char className[16]
[1]
Definition qwizard.cpp:100
if(qFloatDistance(a, b)<(1<< 7))
[0]
QPushButton * pushButton
QObject::connect nullptr
QVBoxLayout * layout
QString title
[35]
QMessageBox msgBox
[0]
QMessageBox messageBox(this)
[2]
QGraphicsWidget * textEdit
myAction setIcon(SomeIcon)
widget render & pixmap
aWidget window() -> setWindowTitle("New Window Title")
[2]
insertRed setText("insert red text")
QMenu menu
[5]
QSizePolicy policy
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:955
bool contains(const AT &t) const noexcept
Definition qlist.h:44
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent