Sort file by their last modified date with QfileSystemModel
-
I want to use QtableView and QfileSystemModel to show all the files in a folder , I want the file list is sorted by their last modified date ,now I have already reimplement QsortFilterProxyModel ,
my code is here
@
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *class SortProxyModel(QSortFilterProxyModel):
def lessThan(self, left_index, right_index):
left_var = left_index.data(Qt.DisplayRole)
right_var = right_index.data(Qt.DisplayRole)
return (left_var <= right_var)if name == 'main':
app =QApplication(sys.argv) ui =QMainWindow() model= QFileSystemModel () model.setRootPath(QDir.currentPath()) proxy = SortProxyModel() proxy.setSourceModel(model) proxy.sort(3) table = QTableView() table.setModel(model); table.setRootIndex(model.index(QDir.currentPath())); ui.setCentralWidget(table) ui.resize(800, 600) ui.show() app.exec_()
@
but I don’t know what index should I give to setRootIndex() , can you help ?