美文网首页
QT文件对话框设置代理

QT文件对话框设置代理

作者: 雯饰太一 | 来源:发表于2023-06-06 06:52 被阅读0次
    class FileFileterProxyModel: public QsortFilterProxyModel {
        protected: virtual bool filterAcceptsRow(int sourceRow,
            const QModelIndex & sourceParent) const {
            QModelIndex index0 = sourceModel() -> index(sourceRow, 0, sourceParent);
            QFileSystemModel * fileModel = qobject_cast < QFileSystemModel * > (sourceModel());
            //I do not want to apply the filter on directions
            if (fileModel == nullptr || fileModel -> isDir(index0)) {
                return true;
            }
            auto fn = fileModel -> fileName(index0);
            //QRegExp rx(".*\\.\\d\\d\\d");
            //只保留.001 .002 .003 ... 等格式的数据,000数据也不需要
            QRegExp rx(".*\\.[0-9]{2}[1-9]{1}");
            return rx.exactMatch(fn);
        }
    };
    
    void fun_test() {
        //获取文件列表
        QString sCurPath = QDir::currentPath();
        QFileDialog myFileDialog((QWidget * ) GIS_GetMainFrameQWidget());
        myFileDialog.setOption(QFileDialog::DontUseNativeDialog);
        myFileDialog.setProxyModel(new FileFileterProxyModel);
        myFileDialog.setNameFilter("UpdateFiles(*.*)");
        myFileDialog.setFileMode(QFileDialog::ExistingFiles);
    
        QStringList sFilePathList;
        if (myFileDialog.exec() == QDialog::Accepted)
            sFilePathList = myFileDialog.selectedFiles();
    
        if (sFilePathList.size() == 0)
            return false;
        sFilePathList.sort();
    }
    

    相关文章

      网友评论

          本文标题:QT文件对话框设置代理

          本文链接:https://www.haomeiwen.com/subject/zpmredtx.html