Read "date" from table

Question:

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.

Asked By: Ajang

||

Answers:

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.

Answered By: Kondwani Simwanza
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.