Search code examples
pythonpyqt5

Read "date" from table


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.


Solution

  • 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.