python - Sort QTableView QDateTime Column instead of string sort -


in qtableview there 4 column. 0th col date in dd-mm-yyyy format. , other 3 column contains string them sorting not problem (can done using qsortfilterproxymodel class) col 0 want sorting right left ( both ascending , descending order).

here simple example of customsortingmodel

self.tableview = qtgui.tableview(self) self.table_model = qtgui.qstandarditemmodel(0, 0) self.proxymodel = customsortingmodel(self)  self.proxymodel.setsourcemodel(self.table_model) self.tableview.setmodel(self.proxymodel)  class customsortingmodel(qtgui.qsortfilterproxymodel):     def lessthan(self,left,right):          col = left.column()          dataleft = left.data()         dataright = right.data()          if col == 2:             dataleft = float(dataleft)             dataright = float(dataright)         elif col == 3:             dataleft = qtcore.qdatetime.fromstring(dataleft, "d/m/yy").addyears(100)             dataright = qtcore.qdatetime.fromstring(dataright, "d/m/yy").addyears(100)          return dataleft < dataright 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -