如何从pyside中的QTableWidget获取表格单元格值?

pra*_*659 3 python

form_shift 是表格名称

tblSessionQTableWidget对象

shift_id=form_shift.tblSession.item(1,0).text()
Run Code Online (Sandbox Code Playgroud)

错误:

AttributeError: 'NoneType' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)

Wee*_*etu 6

这对我来说很好用。也许您的桌子在这些坐标处没有项目?

table = QtGui.QTableWidget(5, 3, self)

for row in range(5):
  for col in range(3):
    table.setItem(row, col, QtGui.QTableWidgetItem("(%d, %d)" % (row, col)))


print("1,0: %s" % table.item(1, 0).text())
Run Code Online (Sandbox Code Playgroud)