PyQt—QTableWidget中的checkBox狀態判斷

1、QTableWidget實現checkBox效果app

利用QTableWidgetItem對象的CheckState屬性,既能顯示QCheckBox,又能讀取狀態ui

table = QtGui.QTableWidget()
checkBox = QtGui.QTableWidgetItem()
checkBox.setCheckState(QtCore.Qt.Unchecked)
table.setItem(i, 0, checkBox)

2、call some function when checkbox state changespa

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)
相關文章
相關標籤/搜索