Get data from every cell from a QTableView

2020-02-29 11:05发布

I need the values from a QtableView, but I do not know how to do that without a signal emitted from the table.

The table takes its values from a txt-file. From the table, I want to work with the values, but without working in the table. The table is just a buffer. So how can I "take" all the values from the table, just pressing a QPushButton, without any signal from the table itself?

1条回答
贪生不怕死
2楼-- · 2020-02-29 11:58

The QTableView just displays the data contained in its model. You have to work with this model to retrieve the data. You must also define how you want to store the values. For instance:

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()))
查看更多
登录 后发表回答