从 QTableView 的每个单元格中获取数据 [英] Get data from every cell from a QTableView

查看:86
本文介绍了从 QTableView 的每个单元格中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

该表从 txt 文件中获取其值.从表中,我想使用这些值,但不在表中工作.该表只是一个缓冲区.那么我怎样才能获取"表格中的所有值,只需按下 QPushButton,而不来自表格本身的任何信号?

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?

推荐答案

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

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()))

这篇关于从 QTableView 的每个单元格中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆