【问题标题】:Show "Windows Libraries" in QTreeView and QFileSystemModel在 QTreeView 和 QFileSystemModel 中显示“Windows 库”
【发布时间】:2015-03-13 00:09:43
【问题描述】:

我的程序中有一个 QTreeView,用于在 Windows 操作系统上选择目录。它有效,但是,一些用户抱怨为了选择我的文档,他们必须展开 C:\Users\\Documents,这很慢。他们更喜欢直接在根级别访问“库”,例如左侧的 Windows 资源管理器(文档、音乐、图片...)。如何使用 QTreeView 和 QFileSystemModel 做到这一点?我在 Qt 5/C++ 中。

编辑:Windows 资源管理器还包含其他项目,我想包括:网络和收藏夹。

【问题讨论】:

    标签: qt qtreeview qfilesystemmodel


    【解决方案1】:

    你需要使用qstandardpaths

    此枚举描述了可以使用 QStandardPaths::writableLocation、QStandardPaths::standardLocations 和 QStandardPaths::displayName 等方法查询的不同位置。

    QStandardPaths::MusicLocation   4   Returns the directory containing the user's music or other audio files. This is a generic value. If no directory specific for music files exists, a sensible fallback for storing user documents is returned.
    
    QStandardPaths::MoviesLocation  5   Returns the directory containing the user's movies and videos. This is a generic value. If no directory specific for movie files exists, a sensible fallback for storing user documents is returned.
    

    【讨论】:

    • 这很好,但问题也是如何将它添加到 QTreeView 和 QFileSystemModel 中。另外,我想在根级别包括“网络”和“收藏夹”,我目前有硬盘驱动器号。我编辑了我的帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多