从QTableView的每个单元格中获取数据

时间:2014-01-22 10:18:37

标签: python pyqt qtableview

我需要来自QtableView的值,但如果没有从表中发出的信号,我不知道如何做到这一点。

该表从txt文件中获取其值。从表中,我想使用值,但没有在表中工作。该表只是一个缓冲区。 那么我怎样才能“获取”表中的所有值,只需按QPushButton,而不会从表中发出任何信号?

1 个答案:

答案 0 :(得分:8)

QTableView只显示其模型中包含的数据。您必须使用此模型来检索数据。您还必须定义要存储值的方式。例如:

model = tableView.model()
data = []
for row in range(model.rowCount()):
  data.append([])
  for column in range(model.columnCount()):
    index = model.index(row, column)
    # We suppose data are strings
    data[row].append(str(model.data(index).toString()))
相关问题