PDA

View Full Version : Create windows explorer with QListView QTreeView



dima
21st July 2010, 06:58
Hi , I trying to create widget looks like Windows explorer. Left side of dialog based on QTreeView and right side is QListView.
My problem is when I set QDirModel ,rootIndex, nameFilter, iconProvider for each side and activating dialog show first time takes 30 second to display.

Any suggestion how to speedup operation.

Lykurg
21st July 2010, 07:17
It's one year ago, I was sitting in front of an "hebrew" windows. So what is on the left and right side of your windows explorer? Are the elements also positioned right to left like hebrew?

But, better use QFileSystemModel instead of QDirModel, this will speed up things a little.

skyperhh
12th January 2012, 20:52
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;
}

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


mainwindow.cpp

#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));
}

7265

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 ???
7266

grayfox
13th January 2012, 10:12
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QFileSystemModel model;
model.setRootPath("");
QTreeView tree;
tree.setModel(&model);

// Demonstrating look and feel features
tree.setAnimated(false);
tree.setIndentation(20);
tree.setSortingEnabled(true);

tree.setWindowTitle(QObject::tr("Dir View"));
tree.resize(640, 480);
tree.show();

return app.exec();
}


The above code is the entire code for the dir view demo, on Windows 7, when expanding to the qt dir, I experience several seconds delay as well.