首次提交
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#include "FileExplorer.h"
|
||||
#include "CustomFileDelegate.h"
|
||||
|
||||
|
||||
FileExplorer::FileExplorer() {
|
||||
model = new QFileSystemModel(this);
|
||||
resize(1000, 800);
|
||||
treeView = new QTreeView(this);
|
||||
treeView->setModel(model);
|
||||
it = new CustomFileDelegate(this, treeView);
|
||||
treeView->setItemDelegate(it);
|
||||
treeView->setHeaderHidden(false);
|
||||
treeView->setColumnWidth(0, 250);
|
||||
treeView->setAnimated(true);
|
||||
treeView->setSortingEnabled(true);
|
||||
treeView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
layout = new QVBoxLayout(this);
|
||||
showRootDir = new QLineEdit;
|
||||
showFocusFile = new QLabel;
|
||||
layout->addWidget(showRootDir);
|
||||
layout->addWidget(treeView);
|
||||
auto bottom = new QHBoxLayout();
|
||||
confirmButton = new QPushButton("确定");
|
||||
cancelButton = new QPushButton("取消");
|
||||
confirmButton->setFixedHeight(height);
|
||||
cancelButton->setFixedHeight(height);
|
||||
|
||||
bottom->addWidget(showFocusFile);
|
||||
bottom->addWidget(confirmButton);
|
||||
bottom->addWidget(cancelButton);
|
||||
layout->addLayout(bottom);
|
||||
changeRoot("D:/");
|
||||
|
||||
connect(showRootDir, &QLineEdit::returnPressed, [this](){
|
||||
changeRoot(showRootDir->text());
|
||||
});
|
||||
connect(treeView, &QTreeView::clicked, [this](const QModelIndex &index) {
|
||||
focus = model->fileInfo(index);
|
||||
showFocusFile->setText(focus.fileName());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user