[SOLVED] QCheckBox in a QTableWidget
-
i created a simple loop in a QTableWidget with checkboxes but i dont know how i get their objectnames.
@
for (int i=0; i < total_items; i++) {
QCheckBox *cb = new QCheckBox();
tableWidget->setCellWidget(i, 0, cb);
tableWidget->setItem(i, 1, new QTableWidgetItem("name" + i));
}
@when i click the OK button, i want to detect if the checkboxes are checked or not but i dont have any idea how to get their objectnames.
hope you could give some advices on how to deal with this. thank you.
-
You can simply loop over the items again, right? Either you store pointers to the checkboxes separately (in a QList<QCheckBox*> or a QVector<QCheckBox*>, or you simply retreive the pointer to the widget again from your tablewidgetitem and cast it to a QCheckBox* again.
Note: QTableWidget can also display checkboxes by itself. No separate widgets needed...
-
Do you know of the "Qt::ItemIsUserCheckable":http://doc.qt.nokia.com/4.7/qt.html#ItemFlag-enum flag for table wiget items (and all other item view/widget classes)?
-
can QTableWidget display checkboxes by itself without the need of seperate widgets ?
plz tell me how. -
i'll checkout Qt::ItemIsUserCheckable .
by the way QList<QCheckBox*> worked wonders thanks.