QFilesystemModel

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFileSystemModel>
#include <QTreeView>
#include <QListView>
#include <QDir>


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    QTreeView * treeview;
   // QListView *listview;
    QFileSystemModel *model;
};

#endif // MAINWINDOW_H



#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    treeview=new QTreeView(this);
    //listview=new QListView(this);
    setCentralWidget(treeview);
    model=new QFileSystemModel(this);
    model->setRootPath(QDir::currentPath());
    treeview->setModel(model);
    treeview->setRootIndex(model->index(QDir::currentPath()));
}

 

 


posted @ 2020-12-27 11:49  deadwood_2016  阅读(136)  评论(0编辑  收藏  举报