我在使用 QTreeView 和 QFileSystemModel 过滤特定文件夹时遇到问题。
我将我的根 QFileSystemModel 设置为一个特定的文件夹 - 这有效。但我只想显示包含.jpg
文件的文件夹。这可能吗?
我过滤.jpg
文件并且有效,但我的 QTreeView 显示所有文件夹,即使是那些没有.jpg
文件的文件夹。因此,如果用户尝试打开某个没有.jpg
文件的文件夹,则不会发生任何事情。
如何隐藏这些文件夹?
注意:下面有部分代码。
QStringList filterTypeFile;
filterTypeFile.append("*.jpg");
this->m_pModelTreeViewImage->setNameFilters(filterTypeFile);
this->m_pModelTreeViewImage->setNameFilterDisables(false);
this->ui->treeViewImages->setModel(this->m_pModelTreeViewImage);