Files
2026-07-29 12:30:40 +08:00

41 lines
1.4 KiB
C++

#include "FileExplorer.h"
#include "CustomFileDelegate.h"
file_explorer::file_explorer() {
model = new QFileSystemModel(this);
resize(1000, 800);
tree_view = new QTreeView(this);
tree_view->setModel(model);
it = new Custom_File_Delegate(this, tree_view);
tree_view->setItemDelegate(it);
tree_view->setHeaderHidden(false);
tree_view->setColumnWidth(0, 250);
tree_view->setAnimated(true);
tree_view->setSortingEnabled(true);
tree_view->setSelectionMode(QAbstractItemView::SingleSelection);
layout = new QVBoxLayout(this);
show_root_dir = new QLineEdit;
showFocusFile = new QLabel;
layout->addWidget(show_root_dir);
layout->addWidget(tree_view);
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);
change_root("D:/");
connect(show_root_dir, &QLineEdit::returnPressed, [this](){
change_root(show_root_dir->text());
});
connect(tree_view, &QTreeView::clicked, [this](const QModelIndex &index) {
focus = model->fileInfo(index);
showFocusFile->setText(focus.fileName());
});
}