解决PyQt5中 QFileSystemModel(),setRootPath()不起作用

from PyQt5.QtWidgets import QTreeView,QFileSystemModel,QApplication

class Main(QTreeView):

def __init__(self):

QTreeView.__init__(self)

model = QFileSystemModel()

dir='/home/'

model.setRootPath(dir)

self.setModel(model)

self.setRootIndex(model.index(dir))

self.doubleClicked.connect(self.test)

def test(self, signal):

file_path=self.model().filePath(signal)

print(file_path)

if __name__ == '__main__':

import sys

app = QApplication(sys.argv)

w = Main()

w.show()

sys.exit(app.exec_())


加入self.setRootIndex(model.index(dir))

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容