英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论