<>QT中判断table Widget复选框状态
<>1. 设置table widget复选框及其行数,列数,内容填充,表头
//设置行数 ui->tableWidget->setRowCount(5); //设置列数
ui->tableWidget->setColumnCount(6); //设置表头 QStringList header; header
<<"标题1"<<"标题2"<<"标题3"<<"标题4"<<"标题5"<<"标题6";
ui->tableWidget->setHorizontalHeaderLabels(header); //隐藏第五列
ui->tableWidget->setColumnHidden(4,true); //填充内容,及设置复选框 for(int crow=0;
crow<5;crow++) { //第一列设置为复选框 QTableWidgetItem *check = new
QTableWidgetItem(QString("")); check->setCheckState(Qt::Unchecked);
ui->tableWidget->setItem(crow, 0 ,check); //填充其他列的内容
ui->tableWidget->setItem(crow,1,new QTableWidgetItem("3"));
ui->tableWidget->setItem(crow,2,new QTableWidgetItem("2"));
ui->tableWidget->setItem(crow,3,new QTableWidgetItem("1"));
ui->tableWidget->setItem(crow,4,new QTableWidgetItem("5")); }
<>2.判断复选框是否被选中
void MainWindow::on_pushButton_clicked() { bool flag = 0; QTableWidgetItem
*cellItem; for(int i= 0; i<5; i++) { //cellItem定位到第一列 cellItem =
ui->tableWidget->item(i,0); //判断第一列的循环中状态 flag = cellItem ->checkState();
if(flag ==1) { qDebug()<<"选中了:"<<i+1; } } }