带有 "Do not show this again" 复选框的 QMessageBox

QMessageBox with a "Do not show this again" checkbox

如何在下方显示带有 "Do not show again" 复选框的消息框?

我想像这样的东西:

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();
}