I have a QTreeWidget with 3 columns. It is used in a search function and the tree holds
- Result name
- Result date
- Number of hits in result for $searchterm.
The default behavior is to sort by date descending. This originally worked perfectly since that was done through the SQL query and just loaded into the tree afterward. However, things got broken when I decided to allow the user to sort by the other columns and not just date.
The dates are in mm/dd/yyyy format but the QTreeWidget ignores the year while sorting in favor of month and day. It seems to want to treat dates like integers. The month and day are sorted correctly but the years are mixed together when they should not be. ( 10/06/2012, 10/06/2011, 10/05/2012, etc.) Is there a way I can tell the QTreeWidget sort function to give year the top priority (so that everything from 2012 is grouped together, everything from 2011 is grouped together, etc.) or even tell it to use a date format in that column?
It’s not sorted as integer, it’s sorted as string. The model you use for the tree view need to return
QDateorQDateTimefor the column in thedata()function.