mardi 14 novembre 2017

How to add a list of checkboxes in a QMessageBox in Qt

I am new in Qt programming, however I am trying to add a list of checkboxes to a Message box which is initiated when you click a button. It work when its just a single check box. But I get stuck when I am trying to add more checkboxes, rather what I get is multiple message boxes pop up. This is my code

QCheckBox *cb = new QCheckBox("node_1");
QCheckBox *cb1 = new QCheckBox("Okay I understand");
QCheckBox *cb2 = new QCheckBox("Okay I understand");
QCheckBox *cb3 = new QCheckBox("Okay I understand");
QCheckBox *cb4 = new QCheckBox("Okay I understand");
QCheckBox *cb5 = new QCheckBox("Okay I understand");
QCheckBox *cb6 = new QCheckBox("Okay I understand");
QCheckBox *cb7 = new QCheckBox("Okay I understand");
QCheckBox *cb8 = new QCheckBox("Okay I understand");
QMessageBox msgbox;
msgbox.setText("Please select nodes");
msgbox.setIcon(QMessageBox::Icon::Question);
msgbox.addButton(QMessageBox::Ok);
msgbox.addButton(QMessageBox::Cancel);
msgbox.setDefaultButton(QMessageBox::Cancel);
msgbox.setCheckBox(cb);
msgbox.setCheckBox(cb1);

QObject::connect(cb, &QCheckBox::stateChanged, [this](int state){

});msgbox.exec();
QObject::connect(cb1, &QCheckBox::stateChanged, [this](int state){

});

msgbox.exec();

}




Aucun commentaire:

Enregistrer un commentaire