-
Notifications
You must be signed in to change notification settings - Fork 4
/
choose.cpp
executable file
·63 lines (57 loc) · 1.5 KB
/
choose.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "choose.h"
#include "ui_choose.h"
#include "QString"
#include "QDir"
#include "QFileDialog"
#include "QDateTime"
Choose::Choose(QString title, bool isFile, QWidget *parent) :
QDialog(parent),
ui(new Ui::Choose)
{
ui->setupUi(this);
this->title = title;
this->isFile = isFile;
this->setWindowTitle(this->title);
if(this->isFile){
ui->label->setText("Files:");
}
}
Choose::~Choose()
{
delete ui;
}
void Choose::on_choose_clicked()
{
if(this->isFile){
QStringList fileList = QFileDialog::getOpenFileNames(this,tr("Open File"), QDir::home().path());
QString file="";
for(int i=0;i<fileList.size();i++){
file += fileList.at(i)+";";
}
if(file != "")
ui->text->setText(file);
}
else
{
//QDir dir;
QString PathName = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::home().path(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if(PathName != "")
ui->text->setText(PathName); //文件名称显示
//dir.mkdir(PathName); //在目录下创建新文件夹
}
}
void Choose::on_result_accepted()
{
value = ui->text->text();
this->accept();
}
void Choose::on_result_rejected()
{
this->reject();
}
QString Choose::getValue(){
return this->value;
}