How to sorting date with QString type in QTableWidget?
Solved
General and Desktop
-
Default item in QTableWidget is QString, when I read date with format dd/MM/yyyy (13/12/2020), sort date column same only sort with first character.
This is date column new load:
This is table date column after sort:
sorting is incorrect!
How to sort date by QString type?
*format I use dd/MM/yyyy -
If you can just store the date as date, not string and it will sort correctly, so instead of
QTableWidgetItem* item = new QTableWidgetItem("12/11/2020");
do
QTableWidgetItem* item = new QTableWidgetItem(); item->setData(Qt::DisplayRole, QDate(2020,11,12));
If you really want strings you can switch to QTableView and implement custom sorting with QSortFilterProxyModel.
-
@Chris-Kawa thank you so much!