自定义高级QFileDialog文件过滤器
2015-06-19 11:23
120 查看
QFileDialog提供了一个函数---setproxyModel。。就是用这个来玩了。就是override filterAcceptsRow的虚函数,里面定制自己的过滤需求。返回bool 下面就是判断是否是目录,只显示目录文件夹。
references:
http://stackoverflow.com/questions/4893122/filtering-in-qfiledialog http://stackoverflow.com/questions/2101100/qfiledialog-filtering-folders
#ifndef PROXY_MODEL_H #define PROXY_MODEL_H #include <QSortFilterProxyModel> class FileFilterProxyModel : public QSortFilterProxyModel { public: FileFilterProxyModel(QObject* parent) :QSortFilterProxyModel(parent){} protected: virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; }; #endif
#include "proxymodel.h" #include <QFileSystemModel> #include <QDebug> bool FileFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); QFileSystemModel* fileModel = qobject_cast<QFileSystemModel*>(sourceModel()); if (fileModel != NULL && fileModel->isDir(index0)) { qDebug() << fileModel->fileName(index0); return true; } else return false; // uncomment to execute default implementation //return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); }
QFileDialog dialog; FileFilterProxyModel* proxyModel = new FileFilterProxyModel(); dialog.setOption(QFileDialog::DontUseNativeDialog); dialog.setProxyModel(proxyModel); dialog.exec();
references:
http://stackoverflow.com/questions/4893122/filtering-in-qfiledialog http://stackoverflow.com/questions/2101100/qfiledialog-filtering-folders
相关文章推荐
- 取消软键盘自动弹出
- Leetcode37: Implement strStr()
- eclipse+php+wamp配置
- Eclipse中SVN切换用户名
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题
- eclipse 操作笔记
- SAFe 从概念到实践 开发人员的“敏捷”之我见
- 解决编译Gh0st时error C2065: 'IDC_HAND' : undeclared identifier
- 算法导论--贪心算法与动态规划(活动选择问题)
- 第三阶段绩效考核
- SVN 目录结构
- java知识点二-TCP和UDP的联系和用途
- linux 配置放火墙端口
- 剖析开源监控Nagios故障
- ssh框架分工与职责
- String format specifier
- leetcode: basic caculator
- 恢复oracle中误删除drop掉的表
- Android--Volley(四)--源码解析
- 超时重发