简体   繁体   English

如何从 QTableWidget 列中获取行数据?

[英]How to get rows data from a QTableWidget Column?

How can I get the value of each row from a specific column in a QTableWidget?如何从 QTableWidget 的特定列中获取每一行的值?

To get the values of all the rows of a given column then you must iterate by obtaining the QTableWidgetItems using the item() method, verify if it is valid and then get the text.要获取给定列的所有行的值,您必须通过使用 item() 方法获取 QTableWidgetItems 进行迭代,验证它是否有效,然后获取文本。

col = ...

data = []
for row in range(tablewidget.rowCount()):
    it = tablewidget.item(row, col)
    text = it.text() if it is not None else ""
    data.append(text)
print(data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM