在QTableWidget中会经常用的checkBox,但是如何判断复选框是否被选中呢,方法是利用QTableWidget::cellChanged()函数,检查单元格内容的变化,然后连接此信号,在槽函数中检测checkBox的状态,代码如下:
01 | QTableWidget *tableWidget = new QTableWidget; |
02 | QTableWidgetItem *firstColumn = new QTableWidgetItem(tr("test")); |
03 | firstColumn->setCheckState(Qt::Checked);//加入复选框 |
04 | connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(changeTest(int, int))); |
05 | void changeTest(int row, int col) |
06 | { |
07 | if(tableWidget ->item(row, col)->checkState() == Qt::Checked) |
08 | ... |
09 | else |
10 | ... |
11 | } |
1990

被折叠的 条评论
为什么被折叠?



