I have encountered a problem after I built a table with QTableWidget: I tried to sort a list of directories based on their creation time.
In the data collection function:
...
mtime = os.path.getmtime(directory)
item['mtime'] = str(mtime)
ltime = time.ctime(mtime)
item['ltime'] = ltime
...
Then in the table creation function:
...
self.table.setItem(row, 1, QtWidgets.QTableWidgetItem(item['ltime']))
self.table.setItem(row, 2, QtWidgets.QTableWidgetItem(item['mtime']))
row += 1
...
And I enabled sorting simply by:
self.table.setSortingEnabled(True)
However when I sort the ltime column, it would only sort based on alphabetical order of strings:
Only when I sort with the mtime column would I get the correct result:
So my question is, is there a method for me to sort based on mtime when I click on the header of ltime column? I would like to hide the mtime column as well, since it would be confusing for users.