从表格中读取 “date”。

huangapple go评论60阅读模式
英文:

Read "date" from table

问题

T=[]
for i in range(self.ui.table_Level_N.rowCount()):
    T.append(self.ui.table_Level_N.item(i,0).text())
英文:

In my GUI, made with Qt Designer, I have table, 6 columns and 5 rows(headers not count). In first column will be date in format "DD/MM/YY". How I can read and save to some variable those dates, for future use in pdf report? Dates will not be used in any operations, just copy from table and send to function that build pdf report, so they can be str format.

I tried this:

T=[]
for i in range(self.ui.table_Level_N.rowCount()):
    T.append(self.ui.table_Level_N.item(i,0))

but got some strange text:

<PyQt5.QtWidgets.QTableWidgetItem object at 0x0000019A24D903A0>

I assumed that it read dates but not in right format.table_Level_N is my table.

答案1

得分: 1

你需要从QTableWidgetItem中获取文本,并将其附加到列表中。尝试这样做:

T = []
for i in range(self.ui.table_Level_N.rowCount()):
    item = self.ui.table_Level_N.item(i, 0)
    T.append(item.text())

这将为你提供你想要的格式中的单元格文本,然后你可以在你的PDF报告中使用它。

英文:

You need to get the text from the QTableWidgetItem and append it to the list. Try this:

T = []
for i in range(self.ui.table_Level_N.rowCount()):
    item = self.ui.table_Level_N.item(i, 0)
    T.append(item.text())

This will give you the text of the cell in the format you want, which you can then use in your PDF report.

huangapple
  • 本文由 发表于 2023年2月8日 20:18:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385694.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定