PyQt:QFileSystemModel 中的当前目录

发布于 2024-10-06 21:54:59 字数 536 浏览 0 评论 0原文

我正在使用一些官方示例中的以下代码:

        model = QFileSystemModel()
        model.setRootPath(QDir.currentPath())
        view = QTreeView(parent=self);
        view.setModel(model)

我希望它能够在树视图中展开目录结构,以便显示运行我的程序的目录。然而,我得到的是从文件系统根开始的未展开的树。我怎样才能做对呢?

我尝试使用 expand,但没有帮助:

        model = QFileSystemModel()
        index = model.index(QDir.currentPath())
        view = QTreeView(parent=self);
        view.setModel(model)
        view.expand(index)

树视图仍然未展开。

I am using following code from some official example:

        model = QFileSystemModel()
        model.setRootPath(QDir.currentPath())
        view = QTreeView(parent=self);
        view.setModel(model)

I expected it to expand directory structure in the tree view so directory from which my program is run would be displayed. What I get, however, is unexpanded tree starting with file system root. How can I make it right?

I tried using expand, but it didn't help:

        model = QFileSystemModel()
        index = model.index(QDir.currentPath())
        view = QTreeView(parent=self);
        view.setModel(model)
        view.expand(index)

The tree view is still unexpanded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2024-10-13 21:54:59

您必须使用QTreeView.expand

You would have to use QTreeView.expand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文