QTableWidget中checkBox如何判断复选框是否被选中

时间:2022-01-22 12:14:18

在QTableWidget中会经常用的checkBox,但是如何判断复选框是否被选中呢,方法是利用QTableWidget::cellChanged()函数,检查单元格内容的变化,然后连接此信号,在槽函数中检测checkBox的状态,代码如下:

查看源代码
< id="highlighter_318552_clipboard" title="复制到剪贴板" type="application/x-shockwave-flash" width="16" height="16" src="
http://klniu.com/wordpress/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/clipboard.swf" menu="false" flashvars="highlighterId=highlighter_318552" wmode="transparent" allowscriptaccess="always">
打印帮助
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 }

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hufeng825/archive/2010/07/30/5776180.aspx