How can I show a message box with a "Do not show again" checkbox below?
I imagine something that looks like this:
Qt 5.2 added the possibility to add a QCheckBox
to a QMessageBox
. Have a look at QMessageBox::setCheckbox
Here is some demo code
if (this->showMsgBox) {
QCheckBox *cb = new QCheckBox("Okay I understand");
QMessageBox msgbox;
msgbox.setText("Am I nerve-wrecking?");
msgbox.setIcon(QMessageBox::Icon::Question);
msgbox.addButton(QMessageBox::Ok);
msgbox.addButton(QMessageBox::Cancel);
msgbox.setDefaultButton(QMessageBox::Cancel);
msgbox.setCheckBox(cb);
QObject::connect(cb, &QCheckBox::stateChanged, [this](int state){
if (static_cast<Qt::CheckState>(state) == Qt::CheckState::Checked) {
this->showMsgBox = false;
}
});
msgbox.exec();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With