美文网首页
解决PyQt5中 QFileSystemModel(),setR

解决PyQt5中 QFileSystemModel(),setR

作者: 哈哈哈哈哈呵呵呵 | 来源:发表于2017-01-15 10:41 被阅读0次

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))

相关文章

网友评论

      本文标题:解决PyQt5中 QFileSystemModel(),setR

      本文链接:https://www.haomeiwen.com/subject/aypybttx.html