一、QTableWidget实现checkBox效果
利用QTableWidgetItem对象的CheckState属性,既能显示QCheckBox,又能读取状态
table = QtGui.QTableWidget()
checkBox = QtGui.QTableWidgetItem()
checkBox.setCheckState(QtCore.Qt.Unchecked)
table.setItem(i, 0, checkBox)
二、call some function when checkbox state change
self.connect(self.table, QtCore.SIGNAL("itemClicked(QTableWidgetItem*)"), self.table_item_clicked)
def table_item_clicked(self, QTableWidgetItem):
check_state = QTableWidgetItem.checkState()
row = QTableWidgetItem.row()
if check_state == QtCore.Qt.Checked:
if row not in self.delete_row:
self.delete_row.append(row)
elif check_state == QtCore.Qt.Unchecked:
if row in self.delete_row:
self.delete_row.remove(row)