How can I show a message box with a "Do not show again" checkbox below?
I imagine something that looks like this:
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 增加了将 a 添加QCheckBox
到 a的可能性QMessageBox
。看看QMessageBox::setCheckbox
这是一些演示代码
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();
}