PyQt4 - QTableView - 如何循环 QTableView
PyQt4 - QTableView - How to loop over QTableView
我试图在 python 中找到一个示例,我可以在其中循环遍历 QTableView 的模型元素并打印整行。
我已经找到了如何遍历选定的行,但在未选择行时没有任何内容。
有人可以帮助我吗?无需告诉我如何创建模型以及如何将其应用于 QTableModel。我只对如何遍历行感兴趣。
我认为您在问题的某些地方混淆了模型和视图...
但是,为什么不简单地获取行数和列数并遍历所有行数:
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))
也许可以美化一下and/or 写得更紧凑,但基本上仅此而已。
还是我遗漏了什么?
我试图在 python 中找到一个示例,我可以在其中循环遍历 QTableView 的模型元素并打印整行。 我已经找到了如何遍历选定的行,但在未选择行时没有任何内容。
有人可以帮助我吗?无需告诉我如何创建模型以及如何将其应用于 QTableModel。我只对如何遍历行感兴趣。
我认为您在问题的某些地方混淆了模型和视图...
但是,为什么不简单地获取行数和列数并遍历所有行数:
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))
也许可以美化一下and/or 写得更紧凑,但基本上仅此而已。 还是我遗漏了什么?