QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
plainmessagebox.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#include "plainmessagebox.h"
9
10auto PlainMessageBox::show(QWidget *parent, QMessageBox::Icon icon,
11 const QString &title, const QString &text,
12 QMessageBox::StandardButtons buttons)
13 -> QMessageBox::StandardButton {
14 QMessageBox box(parent);
15 box.setIcon(icon);
16 box.setWindowTitle(title);
17 // Before the text: set afterwards, the text would already have been laid
18 // out as rich text once.
19 box.setTextFormat(Qt::PlainText);
20 box.setText(text);
21 box.setStandardButtons(buttons);
22 return static_cast<QMessageBox::StandardButton>(box.exec());
23}
24
25auto PlainMessageBox::askYes(QWidget *parent, const QString &title,
26 const QString &text) -> bool {
27 return show(parent, QMessageBox::Question, title, text,
28 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
29}
30
31void PlainMessageBox::warning(QWidget *parent, const QString &title,
32 const QString &text) {
33 show(parent, QMessageBox::Warning, title, text);
34}
35
36void PlainMessageBox::critical(QWidget *parent, const QString &title,
37 const QString &text) {
38 show(parent, QMessageBox::Critical, title, text);
39}
auto show(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok) -> QMessageBox::StandardButton
Show a modal message box with plain text and wait for it.
auto askYes(QWidget *parent, const QString &title, const QString &text) -> bool
Ask a yes/no question in plain text.
void warning(QWidget *parent, const QString &title, const QString &text)
Show a warning in plain text.
void critical(QWidget *parent, const QString &title, const QString &text)
Show an error in plain text.
QMessageBox helpers that force Qt::PlainText so store-controlled names can never be read as rich-text...