Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Sort file by their last modified date with QfileSystemModel
Qt 6.12 LTS is out! See what's new in the release blog

Sort file by their last modified date with QfileSystemModel

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved