Ok,
looking at this video http://www.youtube.com/watch?v=92biLZST6Vg show it very simple ... a my sample is also working.
UI file with treeview and listview:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileSystemModel>
namespace Ui
{
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
private:
Ui::MainWindow *ui;
QFileSystemModel *drivesModel;
QFileSystemModel *filesModel;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileSystemModel>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_treeView_clicked(const QModelIndex &index);
private:
Ui::MainWindow *ui;
QFileSystemModel *drivesModel;
QFileSystemModel *filesModel;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
drivesModel = new QFileSystemModel(this);
drivesModel
->setFilter
(QDir::NoDotAndDotDot |
QDir::Dirs);
drivesModel->setRootPath(sPath);
ui->treeView->setModel(drivesModel);
ui->treeView->hideColumn(1);
ui->treeView->hideColumn(2);
ui->treeView->hideColumn(3);
filesModel = new QFileSystemModel(this);
filesModel
->setFilter
(QDir::NoDotAndDotDot |
QDir::Files);
filesModel->setRootPath(sPath);
ui->listView->setModel(filesModel);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::on_treeView_clicked(const QModelIndex &index
) {
QString sPath
= drivesModel
->fileInfo
(index
).
absoluteFilePath();
ui->listView->setRootIndex(filesModel->setRootPath(sPath));
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString sPath = "C:/";
drivesModel = new QFileSystemModel(this);
drivesModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
drivesModel->setRootPath(sPath);
ui->treeView->setModel(drivesModel);
ui->treeView->hideColumn(1);
ui->treeView->hideColumn(2);
ui->treeView->hideColumn(3);
filesModel = new QFileSystemModel(this);
filesModel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
filesModel->setRootPath(sPath);
ui->listView->setModel(filesModel);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
QString sPath = drivesModel->fileInfo(index).absoluteFilePath();
ui->listView->setRootIndex(filesModel->setRootPath(sPath));
}
To copy to clipboard, switch view to plain text mode
explorer1.png
Visiting the sub-folder "4.8.0" and going back to the top folder "Qt", the listview shows also the sub-folder "4.8.0" (red circle).
Also using QFileSystemModel on windows XP and qt 4.8.0 needs a few seconds at startup...
Any ideas ???
explorer2.png
Bookmarks