资源简介
用Qt来实现这么一个文件浏览器,实现以下功能:
1.可以显示指定目录下的文件列表;
2.鼠标双击文件列表里的文件夹,可以进入其子文件夹,也可返回上一级。
1.可以显示指定目录下的文件列表;
2.鼠标双击文件列表里的文件夹,可以进入其子文件夹,也可返回上一级。
代码片段和文件信息
#include “FileBrower.h“
FileBrower::FileBrower(QWidget *parent Qt::WFlags flags)
: QWidget(parent flags)
{
ui.setupUi(this);
connect(ui.lineEditSIGNAL(returnPressed())thisSLOT(showCurrentDirFiles()));
connect(ui.listWidgetSIGNAL(itemDoubleClicked(QListWidgetItem*))thisSLOT(showNextDirFiles(QListWidgetItem*)));
}
FileBrower::~FileBrower()
{
}
void FileBrower::showNextDirFiles(QListWidgetItem *item)
{
///获取鼠标双击的文件名字
QString strName = item->text();
QDir dir;
//设置路径为当前目录路径
dir.setPath(ui.lineEdit->text());
//重新设置路径
dir.cd(strName);
//更新当前显示路径并显示当前目录下所有文件
ui.lineEdit->setText(dir.absolutePath());
showCurrentDirFiles();
}
void FileBrower::showCurrentDirFiles()
{
//获取当前输入的目录
QDir currentDir(ui.lineEdit->text());
QStringList fileList;
fileList<<“*“;
QFileInfoList infoList = currentDir.entryInfoList(fileListQDir::AllEntriesQDir::DirsFirst);
//在QListWidget里显示文件列表
this->showFileInfoList(infoList);
}
void FileBrower::showFileInfoList(QFileInfoList pInfoList)
{
ui.listWidget->clear();
for(int i=0;i {
QFileInfo tmpInfo = pInfoList.at(i);
QString pFileName = tmpInfo.fileName();
QListWidgetItem *tmpItem = new QListWidgetItem(pFileName);
if(tmpInfo.isDir())
tmpItem->setIcon(*getItemPropertyIcon(1));
else
tmpItem->setIcon(*getItemPropertyIcon(2));
ui.listWidget->addItem(tmpItem);
}
}
QIcon * FileBrower::getItemPropertyIcon(int iType)
{
QDir dir;
QString path = dir.currentPath();
switch(iType)
{
case 1:
return new QIcon(path+“/Folder.png“);
break;
case 2:
return new QIcon(path+“/File.png“);
break;
}
return NULL;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.CA.... 2022 2018-04-29 15:19 fileBrower\fileBrower\File.png
.CA.... 1758 2018-04-29 16:31 fileBrower\fileBrower\FileBrower.cpp
.CA.... 712 2018-04-29 16:13 fileBrower\fileBrower\FileBrower.h
.CA.... 70 2018-04-29 15:55 fileBrower\fileBrower\FileBrower.qrc
.CA.... 766 2018-04-29 16:47 fileBrower\fileBrower\FileBrower.ui
.CA.... 10083 2018-04-29 15:55 fileBrower\fileBrower\fileBrower.vcproj
.CA.... 1471 2018-04-29 16:48 fileBrower\fileBrower\fileBrower.vcproj.Jungle-PC.Jungle.user
.CA.... 7581 2018-04-29 14:52 fileBrower\fileBrower\Folder.png
.CA.... 3030 2018-04-29 16:13 fileBrower\fileBrower\GeneratedFiles\Debug\moc_FileBrower.cpp
.CA.... 692 2018-04-29 16:13 fileBrower\fileBrower\GeneratedFiles\qrc_FileBrower.cpp
.CA.... 2128 2018-04-29 16:47 fileBrower\fileBrower\GeneratedFiles\ui_FileBrower.h
.CA.... 175 2018-04-29 15:55 fileBrower\fileBrower\main.cpp
.CA.... 44032 2018-04-29 16:48 fileBrower\fileBrower.ncb
.CA.... 896 2018-04-29 15:55 fileBrower\fileBrower.sln
.CA..H. 11264 2018-04-29 16:48 fileBrower\fileBrower.suo
.CA.... 3980 2018-04-29 16:47 fileBrower\Win32\Debug\BuildLog.htm
.CA.... 74240 2018-04-29 16:32 fileBrower\Win32\Debug\fileBrower.exe
.CA.... 621 2018-04-29 16:32 fileBrower\Win32\Debug\fileBrower.exe.intermediate.manifest
.CA.... 982256 2018-04-29 16:32 fileBrower\Win32\Debug\fileBrower.ilk
.CA.... 155970 2018-04-29 16:32 fileBrower\Win32\Debug\FileBrower.obj
.CA.... 1330176 2018-04-29 16:32 fileBrower\Win32\Debug\fileBrower.pdb
.CA.... 61980 2018-04-29 16:13 fileBrower\Win32\Debug\main.obj
.CA.... 65676 2018-04-29 16:13 fileBrower\Win32\Debug\moc_FileBrower.obj
.CA.... 65 2018-04-29 16:32 fileBrower\Win32\Debug\mt.dep
.CA.... 12705 2018-04-29 16:13 fileBrower\Win32\Debug\qrc_FileBrower.obj
.CA.... 650240 2018-04-29 16:32 fileBrower\Win32\Debug\vc90.idb
.CA.... 847872 2018-04-29 16:32 fileBrower\Win32\Debug\vc90.pdb
.C.D... 0 2018-04-29 16:47 fileBrower\fileBrower\GeneratedFiles\Debug
.C.D... 0 2018-04-29 15:55 fileBrower\fileBrower\GeneratedFiles\Release
.C.D... 0 2018-04-29 16:47 fileBrower\fileBrower\GeneratedFiles
............此处省略8个文件信息
- 上一篇:BASIC语言编程初学者手册
- 下一篇:Opencv2.4.12 SVM手写数字识别
评论
共有 条评论