我的程序中有一个 QTreeView,用于在 Windows 操作系统上选择目录。它有效,但是,一些用户抱怨为了选择我的文档,他们必须展开 C:\Users\<user name>\Documents,这很慢。他们更喜欢直接在根级别访问“库”,例如左侧的 Windows 资源管理器(文档、音乐、图片...)。如何使用 QTreeView 和 QFileSystemModel 做到这一点?我在 Qt 5/C++ 中。
编辑:Windows 资源管理器还包含其他项目,我想包括:网络和收藏夹。
我的程序中有一个 QTreeView,用于在 Windows 操作系统上选择目录。它有效,但是,一些用户抱怨为了选择我的文档,他们必须展开 C:\Users\<user name>\Documents,这很慢。他们更喜欢直接在根级别访问“库”,例如左侧的 Windows 资源管理器(文档、音乐、图片...)。如何使用 QTreeView 和 QFileSystemModel 做到这一点?我在 Qt 5/C++ 中。
编辑:Windows 资源管理器还包含其他项目,我想包括:网络和收藏夹。
您需要使用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.