123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "StandardManageView.h"
- #include <QFileIconProvider>
- #include <QResizeEvent>
- #include <QVBoxLayout>
- #include <QDesktopServices>
- StandardManageView::StandardManageView(QWidget *parent) : QWidget(parent)
- {
- QVBoxLayout *vLayout = new QVBoxLayout;
- m_dir = "D:\\FireFly\\QFD2\\文档";
- m_fileModel = new QFileSystemModel();
- m_fileModel->setRootPath("D:/");
- QStringList nameFilter = { "*.doc", "*.docx", "*.xml", "*.xlsx", "*.xls" };
- m_fileModel->setNameFilterDisables(false);
- m_fileModel->setNameFilters(nameFilter);
- m_fileModel->iconProvider()->setOptions(QFileIconProvider::DontUseCustomDirectoryIcons);
- m_treeView = new QTreeView(this);
- m_treeView->setModel(m_fileModel);
- m_treeView->setRootIndex(m_fileModel->index(m_dir));
- vLayout->addWidget(m_treeView);
- // Demonstrating look and feel features
- m_treeView->setAnimated(false);
- m_treeView->setIndentation(20);
- m_treeView->setSortingEnabled(true);
- CDelegate *pDelegate = new CDelegate(this);
- m_treeView->setItemDelegate(pDelegate);
- connect(m_treeView, &QTreeView::doubleClicked, this, &StandardManageView::onDoubleClick);
- setLayout(vLayout);
- }
- void StandardManageView::resizeEvent(QResizeEvent *event)
- {
- m_treeView->setColumnWidth(0, this->width() / 3);
- }
- void StandardManageView::onDoubleClick(const QModelIndex &index)
- {
- if (index.row() < 0 || index.column() < 0) {
- return;
- }
- QString filePath = m_fileModel->filePath(index);
- // qDebug() << filePath;
- if (!filePath.isEmpty()) {
- QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
- }
- }
|