之前在做qtablewidget中的复选框,通过currentindex获取不到,一直显示复选框的行号是-1
就像这样:
def checkBoxClicked(self, a):
try:
if a == 2:
row_index = self.tableWidget.currentIndex().row()
s = self.sender()
print(row_index)
print(s)
except Exception as e:
print("异常是", e)
后来找了一些资料进行更正,就可以正确获取到复选框的行号了:
def checkBoxClicked(self, a):
try:
if a == Qt.Checked:
s = self.sender()
row = self.tableWidget.indexAt(s.parent().pos()).row() # 获取控件checkbox所在的行号
print("选中的是", row)
except Exception as e:
print("异常是", e)
return row