diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-10-26 20:53:49 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-11-03 15:43:58 +0100 |
commit | b2b941823e861269772815743bd6b11c45100f08 (patch) | |
tree | 78cad4678fd89bd6e9a8b33f62fe0110c17a0bb1 /examples/widgets | |
parent | 826dc56d3a941447d02fad48a47441f2329af0bf (diff) |
Exercise QMessageBox::setInformativeText() in standard dialogs example
Change-Id: Id54a6d93e22fcb6622b434e3766baedb581d6b79
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/dialogs/standarddialogs/dialog.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index 443101e421..5ce992434a 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -7,8 +7,9 @@ #define MESSAGE \ Dialog::tr("<p>Message boxes have a caption, a text, " \ - "and any number of buttons, each with standard or custom texts." \ - "<p>Click a button to close the message box. Pressing the Esc button " \ + "and any number of buttons, each with standard or custom texts.") +#define INFORMATIVE_TEXT \ + Dialog::tr("<p>Click a button to close the message box. Pressing the Escape key " \ "will activate the detected escape button (if any).") #define MESSAGE_DETAILS \ Dialog::tr("If a message box has detailed text, the user can reveal it " \ @@ -413,10 +414,13 @@ void Dialog::setSaveFileName() void Dialog::criticalMessage() { - QMessageBox::StandardButton reply; - reply = QMessageBox::critical(this, tr("QMessageBox::critical()"), - MESSAGE, - QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore); + QMessageBox msgBox(QMessageBox::Critical, tr("QMessageBox::critical()"), + MESSAGE, { }, this); + msgBox.setInformativeText(INFORMATIVE_TEXT); + msgBox.addButton(QMessageBox::Abort); + msgBox.addButton(QMessageBox::Retry); + msgBox.addButton(QMessageBox::Ignore); + int reply = msgBox.exec(); if (reply == QMessageBox::Abort) criticalLabel->setText(tr("Abort")); else if (reply == QMessageBox::Retry) @@ -427,9 +431,10 @@ void Dialog::criticalMessage() void Dialog::informationMessage() { - QMessageBox::StandardButton reply; - reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE); - if (reply == QMessageBox::Ok) + QMessageBox msgBox(QMessageBox::Information, tr("QMessageBox::information()"), + MESSAGE, { }, this); + msgBox.setInformativeText(INFORMATIVE_TEXT); + if (msgBox.exec() == QMessageBox::Ok) informationLabel->setText(tr("OK")); else informationLabel->setText(tr("Escape")); @@ -437,10 +442,13 @@ void Dialog::informationMessage() void Dialog::questionMessage() { - QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, tr("QMessageBox::question()"), - MESSAGE, - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + QMessageBox msgBox(QMessageBox::Question, tr("QMessageBox::question()"), + MESSAGE, { }, this); + msgBox.setInformativeText(INFORMATIVE_TEXT); + msgBox.addButton(QMessageBox::Yes); + msgBox.addButton(QMessageBox::No); + msgBox.addButton(QMessageBox::Cancel); + int reply = msgBox.exec(); if (reply == QMessageBox::Yes) questionLabel->setText(tr("Yes")); else if (reply == QMessageBox::No) @@ -453,6 +461,7 @@ void Dialog::warningMessage() { QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"), MESSAGE, { }, this); + msgBox.setInformativeText(INFORMATIVE_TEXT); msgBox.setDetailedText(MESSAGE_DETAILS); msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole); msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole); |