Qt树视图与Pyside [英] Qt tree view with Pyside

查看:141
本文介绍了Qt树视图与Pyside的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序目录中有两个文件夹。我需要它们以树状视图显示,它们应该是可扩展的。如何定义树形视图中的文件夹?如果有人可以给我看一个简单的例子。我知道文件夹的名称。

I have two folders in program directory. I need them to show in tree view, they should be expandable. How can I define what folder will be in tree view? If anyone canshow me an easy example. I know names of folders.

我正在使用Python 2.7和Win 8。

I´m using Python 2.7 and Win 8.

推荐答案

您可以使用 QTreeView QFileSystemModel 来做到这一点:

You can do that with QTreeView and QFileSystemModel:

model = QFileSystemModel();
model.setRootPath(QDir.currentPath())
tree = QTreeView()
tree.setModel(model)
tree.setRootIndex(model.index(QDir.currentPath()))
tree.show()

这篇关于Qt树视图与Pyside的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆