plɹoM ollǝH

ǝldɯᴉs puɐ llɐɯs ʇᴉ dǝǝʞ

QFileSystemModel + QListView Auto Scrolling on Init

QFileSystemModelにはdirectoryLoadedというSignalがあるのでそこで処理する

default_path = '*****'

def on_directory_loaded():
    i = self._model.index(default_path)
    view.setCurrentIndex(i)
    view.scrollTo(i, QAbstractItemView.EnsureVisible)

model = QFileSystemModel()
model.directoryLoaded.connect(on_directory_loaded)
index = model.setRootPath(*****)
view = QListView()
view.setModel(model)
view.setRootIndex(index)
view.show()