1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51#include <QtWidgets>
52
53#include "dialog.h"
54
55#define MESSAGE \
56 Dialog::tr("<p>Message boxes have a caption, a text, " \
57 "and any number of buttons, each with standard or custom texts." \
58 "<p>Click a button to close the message box. Pressing the Esc button " \
59 "will activate the detected escape button (if any).")
60#define MESSAGE_DETAILS \
61 Dialog::tr("If a message box has detailed text, the user can reveal it " \
62 "by pressing the Show Details... button.")
63
64
65class DialogOptionsWidget : public QGroupBox
66{
67public:
68 explicit DialogOptionsWidget(QWidget *parent = nullptr);
69
70 void addCheckBox(const QString &text, int value);
71 void addSpacer();
72 int value() const;
73
74private:
75 typedef QPair<QCheckBox *, int> CheckBoxEntry;
76 QVBoxLayout *layout;
77 QList<CheckBoxEntry> checkBoxEntries;
78};
79
80DialogOptionsWidget::DialogOptionsWidget(QWidget *parent) :
81 QGroupBox(parent) , layout(new QVBoxLayout)
82{
83 setTitle(Dialog::tr(s: "Options"));
84 setLayout(layout);
85}
86
87void DialogOptionsWidget::addCheckBox(const QString &text, int value)
88{
89 QCheckBox *checkBox = new QCheckBox(text);
90 layout->addWidget(checkBox);
91 checkBoxEntries.append(t: CheckBoxEntry(checkBox, value));
92}
93
94void DialogOptionsWidget::addSpacer()
95{
96 layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
97}
98
99int DialogOptionsWidget::value() const
100{
101 int result = 0;
102 for (const CheckBoxEntry &checkboxEntry : qAsConst(t: checkBoxEntries)) {
103 if (checkboxEntry.first->isChecked())
104 result |= checkboxEntry.second;
105 }
106 return result;
107}
108
109Dialog::Dialog(QWidget *parent)
110 : QWidget(parent)
111{
112 QVBoxLayout *verticalLayout;
113 if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
114 QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
115 QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName(), this);
116 horizontalLayout->addWidget(groupBox);
117 verticalLayout = new QVBoxLayout(groupBox);
118 } else {
119 verticalLayout = new QVBoxLayout(this);
120 }
121
122 QToolBox *toolbox = new QToolBox;
123 verticalLayout->addWidget(toolbox);
124
125 errorMessageDialog = new QErrorMessage(this);
126
127 int frameStyle = QFrame::Sunken | QFrame::Panel;
128
129 integerLabel = new QLabel;
130 integerLabel->setFrameStyle(frameStyle);
131 QPushButton *integerButton =
132 new QPushButton(tr(s: "QInputDialog::get&Int()"));
133
134 doubleLabel = new QLabel;
135 doubleLabel->setFrameStyle(frameStyle);
136 QPushButton *doubleButton =
137 new QPushButton(tr(s: "QInputDialog::get&Double()"));
138
139 itemLabel = new QLabel;
140 itemLabel->setFrameStyle(frameStyle);
141 QPushButton *itemButton = new QPushButton(tr(s: "QInputDialog::getIte&m()"));
142
143 textLabel = new QLabel;
144 textLabel->setFrameStyle(frameStyle);
145 QPushButton *textButton = new QPushButton(tr(s: "QInputDialog::get&Text()"));
146
147 multiLineTextLabel = new QLabel;
148 multiLineTextLabel->setFrameStyle(frameStyle);
149 QPushButton *multiLineTextButton = new QPushButton(tr(s: "QInputDialog::get&MultiLineText()"));
150
151 colorLabel = new QLabel;
152 colorLabel->setFrameStyle(frameStyle);
153 QPushButton *colorButton = new QPushButton(tr(s: "QColorDialog::get&Color()"));
154
155 fontLabel = new QLabel;
156 fontLabel->setFrameStyle(frameStyle);
157 QPushButton *fontButton = new QPushButton(tr(s: "QFontDialog::get&Font()"));
158
159 directoryLabel = new QLabel;
160 directoryLabel->setFrameStyle(frameStyle);
161 QPushButton *directoryButton =
162 new QPushButton(tr(s: "QFileDialog::getE&xistingDirectory()"));
163
164 openFileNameLabel = new QLabel;
165 openFileNameLabel->setFrameStyle(frameStyle);
166 QPushButton *openFileNameButton =
167 new QPushButton(tr(s: "QFileDialog::get&OpenFileName()"));
168
169 openFileNamesLabel = new QLabel;
170 openFileNamesLabel->setFrameStyle(frameStyle);
171 QPushButton *openFileNamesButton =
172 new QPushButton(tr(s: "QFileDialog::&getOpenFileNames()"));
173
174 saveFileNameLabel = new QLabel;
175 saveFileNameLabel->setFrameStyle(frameStyle);
176 QPushButton *saveFileNameButton =
177 new QPushButton(tr(s: "QFileDialog::get&SaveFileName()"));
178
179 criticalLabel = new QLabel;
180 criticalLabel->setFrameStyle(frameStyle);
181 QPushButton *criticalButton =
182 new QPushButton(tr(s: "QMessageBox::critica&l()"));
183
184 informationLabel = new QLabel;
185 informationLabel->setFrameStyle(frameStyle);
186 QPushButton *informationButton =
187 new QPushButton(tr(s: "QMessageBox::i&nformation()"));
188
189 questionLabel = new QLabel;
190 questionLabel->setFrameStyle(frameStyle);
191 QPushButton *questionButton =
192 new QPushButton(tr(s: "QMessageBox::&question()"));
193
194 warningLabel = new QLabel;
195 warningLabel->setFrameStyle(frameStyle);
196 QPushButton *warningButton = new QPushButton(tr(s: "QMessageBox::&warning()"));
197
198 errorLabel = new QLabel;
199 errorLabel->setFrameStyle(frameStyle);
200 QPushButton *errorButton =
201 new QPushButton(tr(s: "QErrorMessage::showM&essage()"));
202
203 connect(sender: integerButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setInteger);
204 connect(sender: doubleButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setDouble);
205 connect(sender: itemButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setItem);
206 connect(sender: textButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setText);
207 connect(sender: multiLineTextButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setMultiLineText);
208 connect(sender: colorButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setColor);
209 connect(sender: fontButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::setFont);
210 connect(sender: directoryButton, signal: &QAbstractButton::clicked,
211 receiver: this, slot: &Dialog::setExistingDirectory);
212 connect(sender: openFileNameButton, signal: &QAbstractButton::clicked,
213 receiver: this, slot: &Dialog::setOpenFileName);
214 connect(sender: openFileNamesButton, signal: &QAbstractButton::clicked,
215 receiver: this, slot: &Dialog::setOpenFileNames);
216 connect(sender: saveFileNameButton, signal: &QAbstractButton::clicked,
217 receiver: this, slot: &Dialog::setSaveFileName);
218 connect(sender: criticalButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::criticalMessage);
219 connect(sender: informationButton, signal: &QAbstractButton::clicked,
220 receiver: this, slot: &Dialog::informationMessage);
221 connect(sender: questionButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::questionMessage);
222 connect(sender: warningButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::warningMessage);
223 connect(sender: errorButton, signal: &QAbstractButton::clicked, receiver: this, slot: &Dialog::errorMessage);
224
225 QWidget *page = new QWidget;
226 QGridLayout *layout = new QGridLayout(page);
227 layout->setColumnStretch(column: 1, stretch: 1);
228 layout->setColumnMinimumWidth(column: 1, minSize: 250);
229 layout->addWidget(integerButton, row: 0, column: 0);
230 layout->addWidget(integerLabel, row: 0, column: 1);
231 layout->addWidget(doubleButton, row: 1, column: 0);
232 layout->addWidget(doubleLabel, row: 1, column: 1);
233 layout->addWidget(itemButton, row: 2, column: 0);
234 layout->addWidget(itemLabel, row: 2, column: 1);
235 layout->addWidget(textButton, row: 3, column: 0);
236 layout->addWidget(textLabel, row: 3, column: 1);
237 layout->addWidget(multiLineTextButton, row: 4, column: 0);
238 layout->addWidget(multiLineTextLabel, row: 4, column: 1);
239 layout->addItem(item: new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), row: 5, column: 0);
240 toolbox->addItem(item: page, text: tr(s: "Input Dialogs"));
241
242 const QString doNotUseNativeDialog = tr(s: "Do not use native dialog");
243
244 page = new QWidget;
245 layout = new QGridLayout(page);
246 layout->setColumnStretch(column: 1, stretch: 1);
247 layout->addWidget(colorButton, row: 0, column: 0);
248 layout->addWidget(colorLabel, row: 0, column: 1);
249 colorDialogOptionsWidget = new DialogOptionsWidget;
250 colorDialogOptionsWidget->addCheckBox(text: doNotUseNativeDialog, value: QColorDialog::DontUseNativeDialog);
251 colorDialogOptionsWidget->addCheckBox(text: tr(s: "Show alpha channel") , value: QColorDialog::ShowAlphaChannel);
252 colorDialogOptionsWidget->addCheckBox(text: tr(s: "No buttons") , value: QColorDialog::NoButtons);
253 layout->addItem(item: new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), row: 1, column: 0);
254 layout->addWidget(colorDialogOptionsWidget, row: 2, column: 0, rowSpan: 1 ,columnSpan: 2);
255
256 toolbox->addItem(item: page, text: tr(s: "Color Dialog"));
257
258 page = new QWidget;
259 layout = new QGridLayout(page);
260 layout->setColumnStretch(column: 1, stretch: 1);
261 layout->addWidget(fontButton, row: 0, column: 0);
262 layout->addWidget(fontLabel, row: 0, column: 1);
263 fontDialogOptionsWidget = new DialogOptionsWidget;
264 fontDialogOptionsWidget->addCheckBox(text: doNotUseNativeDialog, value: QFontDialog::DontUseNativeDialog);
265 fontDialogOptionsWidget->addCheckBox(text: tr(s: "Show scalable fonts"), value: QFontDialog::ScalableFonts);
266 fontDialogOptionsWidget->addCheckBox(text: tr(s: "Show non scalable fonts"), value: QFontDialog::NonScalableFonts);
267 fontDialogOptionsWidget->addCheckBox(text: tr(s: "Show monospaced fonts"), value: QFontDialog::MonospacedFonts);
268 fontDialogOptionsWidget->addCheckBox(text: tr(s: "Show proportional fonts"), value: QFontDialog::ProportionalFonts);
269 fontDialogOptionsWidget->addCheckBox(text: tr(s: "No buttons") , value: QFontDialog::NoButtons);
270 layout->addItem(item: new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), row: 1, column: 0);
271 layout->addWidget(fontDialogOptionsWidget, row: 2, column: 0, rowSpan: 1 ,columnSpan: 2);
272 toolbox->addItem(item: page, text: tr(s: "Font Dialog"));
273
274 page = new QWidget;
275 layout = new QGridLayout(page);
276 layout->setColumnStretch(column: 1, stretch: 1);
277 layout->addWidget(directoryButton, row: 0, column: 0);
278 layout->addWidget(directoryLabel, row: 0, column: 1);
279 layout->addWidget(openFileNameButton, row: 1, column: 0);
280 layout->addWidget(openFileNameLabel, row: 1, column: 1);
281 layout->addWidget(openFileNamesButton, row: 2, column: 0);
282 layout->addWidget(openFileNamesLabel, row: 2, column: 1);
283 layout->addWidget(saveFileNameButton, row: 3, column: 0);
284 layout->addWidget(saveFileNameLabel, row: 3, column: 1);
285 fileDialogOptionsWidget = new DialogOptionsWidget;
286 fileDialogOptionsWidget->addCheckBox(text: doNotUseNativeDialog, value: QFileDialog::DontUseNativeDialog);
287 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Show directories only"), value: QFileDialog::ShowDirsOnly);
288 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Do not resolve symlinks"), value: QFileDialog::DontResolveSymlinks);
289 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Do not confirm overwrite"), value: QFileDialog::DontConfirmOverwrite);
290 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Readonly"), value: QFileDialog::ReadOnly);
291 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Hide name filter details"), value: QFileDialog::HideNameFilterDetails);
292 fileDialogOptionsWidget->addCheckBox(text: tr(s: "Do not use custom directory icons (Windows)"), value: QFileDialog::DontUseCustomDirectoryIcons);
293 layout->addItem(item: new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), row: 4, column: 0);
294 layout->addWidget(fileDialogOptionsWidget, row: 5, column: 0, rowSpan: 1 ,columnSpan: 2);
295 toolbox->addItem(item: page, text: tr(s: "File Dialogs"));
296
297 page = new QWidget;
298 layout = new QGridLayout(page);
299 layout->setColumnStretch(column: 1, stretch: 1);
300 layout->addWidget(criticalButton, row: 0, column: 0);
301 layout->addWidget(criticalLabel, row: 0, column: 1);
302 layout->addWidget(informationButton, row: 1, column: 0);
303 layout->addWidget(informationLabel, row: 1, column: 1);
304 layout->addWidget(questionButton, row: 2, column: 0);
305 layout->addWidget(questionLabel, row: 2, column: 1);
306 layout->addWidget(warningButton, row: 3, column: 0);
307 layout->addWidget(warningLabel, row: 3, column: 1);
308 layout->addWidget(errorButton, row: 4, column: 0);
309 layout->addWidget(errorLabel, row: 4, column: 1);
310 layout->addItem(item: new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), row: 5, column: 0);
311 toolbox->addItem(item: page, text: tr(s: "Message Boxes"));
312
313 setWindowTitle(QGuiApplication::applicationDisplayName());
314}
315
316void Dialog::setInteger()
317{
318//! [0]
319 bool ok;
320 int i = QInputDialog::getInt(parent: this, title: tr(s: "QInputDialog::getInt()"),
321 label: tr(s: "Percentage:"), value: 25, minValue: 0, maxValue: 100, step: 1, ok: &ok);
322 if (ok)
323 integerLabel->setText(tr(s: "%1%").arg(a: i));
324//! [0]
325}
326
327void Dialog::setDouble()
328{
329//! [1]
330 bool ok;
331 double d = QInputDialog::getDouble(parent: this, title: tr(s: "QInputDialog::getDouble()"),
332 label: tr(s: "Amount:"), value: 37.56, minValue: -10000, maxValue: 10000, decimals: 2, ok: &ok,
333 flags: Qt::WindowFlags(), step: 1);
334 if (ok)
335 doubleLabel->setText(QString("$%1").arg(a: d));
336//! [1]
337}
338
339void Dialog::setItem()
340{
341//! [2]
342 QStringList items;
343 items << tr(s: "Spring") << tr(s: "Summer") << tr(s: "Fall") << tr(s: "Winter");
344
345 bool ok;
346 QString item = QInputDialog::getItem(parent: this, title: tr(s: "QInputDialog::getItem()"),
347 label: tr(s: "Season:"), items, current: 0, editable: false, ok: &ok);
348 if (ok && !item.isEmpty())
349 itemLabel->setText(item);
350//! [2]
351}
352
353void Dialog::setText()
354{
355//! [3]
356 bool ok;
357 QString text = QInputDialog::getText(parent: this, title: tr(s: "QInputDialog::getText()"),
358 label: tr(s: "User name:"), echo: QLineEdit::Normal,
359 text: QDir::home().dirName(), ok: &ok);
360 if (ok && !text.isEmpty())
361 textLabel->setText(text);
362//! [3]
363}
364
365void Dialog::setMultiLineText()
366{
367//! [4]
368 bool ok;
369 QString text = QInputDialog::getMultiLineText(parent: this, title: tr(s: "QInputDialog::getMultiLineText()"),
370 label: tr(s: "Address:"), text: "John Doe\nFreedom Street", ok: &ok);
371 if (ok && !text.isEmpty())
372 multiLineTextLabel->setText(text);
373//! [4]
374}
375
376void Dialog::setColor()
377{
378 const QColorDialog::ColorDialogOptions options = QFlag(colorDialogOptionsWidget->value());
379 const QColor color = QColorDialog::getColor(initial: Qt::green, parent: this, title: "Select Color", options);
380
381 if (color.isValid()) {
382 colorLabel->setText(color.name());
383 colorLabel->setPalette(QPalette(color));
384 colorLabel->setAutoFillBackground(true);
385 }
386}
387
388void Dialog::setFont()
389{
390 const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value());
391 bool ok;
392 QFont font = QFontDialog::getFont(ok: &ok, initial: QFont(fontLabel->text()), parent: this, title: "Select Font", options);
393 if (ok) {
394 fontLabel->setText(font.key());
395 fontLabel->setFont(font);
396 }
397}
398
399void Dialog::setExistingDirectory()
400{
401 QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
402 options |= QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
403 QString directory = QFileDialog::getExistingDirectory(parent: this,
404 caption: tr(s: "QFileDialog::getExistingDirectory()"),
405 dir: directoryLabel->text(),
406 options);
407 if (!directory.isEmpty())
408 directoryLabel->setText(directory);
409}
410
411void Dialog::setOpenFileName()
412{
413 const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
414 QString selectedFilter;
415 QString fileName = QFileDialog::getOpenFileName(parent: this,
416 caption: tr(s: "QFileDialog::getOpenFileName()"),
417 dir: openFileNameLabel->text(),
418 filter: tr(s: "All Files (*);;Text Files (*.txt)"),
419 selectedFilter: &selectedFilter,
420 options);
421 if (!fileName.isEmpty())
422 openFileNameLabel->setText(fileName);
423}
424
425void Dialog::setOpenFileNames()
426{
427 const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
428 QString selectedFilter;
429 QStringList files = QFileDialog::getOpenFileNames(
430 parent: this, caption: tr(s: "QFileDialog::getOpenFileNames()"),
431 dir: openFilesPath,
432 filter: tr(s: "All Files (*);;Text Files (*.txt)"),
433 selectedFilter: &selectedFilter,
434 options);
435 if (files.count()) {
436 openFilesPath = files[0];
437 openFileNamesLabel->setText(QString("[%1]").arg(a: files.join(sep: ", ")));
438 }
439}
440
441void Dialog::setSaveFileName()
442{
443 const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
444 QString selectedFilter;
445 QString fileName = QFileDialog::getSaveFileName(parent: this,
446 caption: tr(s: "QFileDialog::getSaveFileName()"),
447 dir: saveFileNameLabel->text(),
448 filter: tr(s: "All Files (*);;Text Files (*.txt)"),
449 selectedFilter: &selectedFilter,
450 options);
451 if (!fileName.isEmpty())
452 saveFileNameLabel->setText(fileName);
453}
454
455void Dialog::criticalMessage()
456{
457 QMessageBox::StandardButton reply;
458 reply = QMessageBox::critical(parent: this, title: tr(s: "QMessageBox::critical()"),
459 MESSAGE,
460 buttons: QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
461 if (reply == QMessageBox::Abort)
462 criticalLabel->setText(tr(s: "Abort"));
463 else if (reply == QMessageBox::Retry)
464 criticalLabel->setText(tr(s: "Retry"));
465 else
466 criticalLabel->setText(tr(s: "Ignore"));
467}
468
469void Dialog::informationMessage()
470{
471 QMessageBox::StandardButton reply;
472 reply = QMessageBox::information(parent: this, title: tr(s: "QMessageBox::information()"), MESSAGE);
473 if (reply == QMessageBox::Ok)
474 informationLabel->setText(tr(s: "OK"));
475 else
476 informationLabel->setText(tr(s: "Escape"));
477}
478
479void Dialog::questionMessage()
480{
481 QMessageBox::StandardButton reply;
482 reply = QMessageBox::question(parent: this, title: tr(s: "QMessageBox::question()"),
483 MESSAGE,
484 buttons: QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
485 if (reply == QMessageBox::Yes)
486 questionLabel->setText(tr(s: "Yes"));
487 else if (reply == QMessageBox::No)
488 questionLabel->setText(tr(s: "No"));
489 else
490 questionLabel->setText(tr(s: "Cancel"));
491}
492
493void Dialog::warningMessage()
494{
495 QMessageBox msgBox(QMessageBox::Warning, tr(s: "QMessageBox::warning()"),
496 MESSAGE, { }, this);
497 msgBox.setDetailedText(MESSAGE_DETAILS);
498 msgBox.addButton(text: tr(s: "Save &Again"), role: QMessageBox::AcceptRole);
499 msgBox.addButton(text: tr(s: "&Continue"), role: QMessageBox::RejectRole);
500 if (msgBox.exec() == QMessageBox::AcceptRole)
501 warningLabel->setText(tr(s: "Save Again"));
502 else
503 warningLabel->setText(tr(s: "Continue"));
504
505}
506
507void Dialog::errorMessage()
508{
509 errorMessageDialog->showMessage(
510 message: tr(s: "This dialog shows and remembers error messages. "
511 "If the checkbox is checked (as it is by default), "
512 "the shown message will be shown again, "
513 "but if the user unchecks the box the message "
514 "will not appear again if QErrorMessage::showMessage() "
515 "is called with the same message."));
516 errorLabel->setText(tr(s: "If the box is unchecked, the message "
517 "won't appear again."));
518}
519

source code of qtbase/examples/widgets/dialogs/standarddialogs/dialog.cpp