答案 0 :(得分:12)
Qt 5.2增加了向QCheckBox
添加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();
}