Simple File browser / file chooser in Python program with Qt-GUI?

有些话、适合烂在心里 提交于 2019-12-03 03:39:05
Justin Peel

You need to set the root index to the appropriate one in the file model. You can do this by adding the following line to the end of the clicked() function:

self.file_view.setRootIndex(self.filemodel.index(dir_path))

I was able to figure it out from my experience using Qt in C++. The documentation for Qt in C++ is really quite good if you can figure out how it translates to Python. I was able to figure this out by looking at the QFileSystemModel documentation.

You need to set the root index of the files list view:

def clicked(self, index):
    # the signal passes the index of the clicked item
    dir_path = self.filemodel.filePath(index)
    root_index = self.filemodel.setRootPath(dir_path)
    self.file_view.setRootIndex(root_index)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!