python - PyQt4 - QTableView - 如何循环 QTableView

标签 python pyqt4 qtableview

我试图在 python 中找到一个示例,在其中我可以循环 QTableView 的模型元素并打印整行。 我已经找到了如何循环选定的行,但在未选择行时什么也没有。

有人可以帮助我吗?无需告诉我如何创建模型以及如何将其应用到 QTableModel。我只感兴趣如何迭代行。

最佳答案

我认为您在问题中的某些地方混淆了模型和 View ......

但是,为什么不简单地获取行数和列数并循环遍历所有行数和列数:

for irow in xrange(model.rowCount()):
    row = []
    for icol in xrange(model.columnCount()):
        cell = model.data(model.createIndex(irow, icol))
        row.append(cell)
    # print all elems per row
    print ', '.join(str(c) for c in row))

事情可能可以被美化和/或以更紧凑的方式编写,但这基本上就是全部。 或者我错过了什么?

关于python - PyQt4 - QTableView - 如何循环 QTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32748064/

相关文章:

python - 如何从数据框中找到句子中单词和字符的最大数量?

python - 无法比较 Postgresql sqlalchemy.exc.ProgrammingError ProgrammingError : (ProgrammingError) can't adapt type 'time.struct_time' 中的日期时间

python - 在 PyQt 中设置工具提示的文本颜色

python - PyQt GUI 在 Python 中多线程时卡住,直到线程完成

python-3.x - 使光标接近时显示工具栏

c++ - QTableView、QTableWidget 和 QStandardItemModel?

python - 如何获得 Python 程序的执行时间?

python - 将对象元组转换为字符串元组

c++ - 无法连接(空)::selectionChanged 到 QTableView

python - 在 QTableView 中显示某些列