Create windows explorer with QListView QTreeView
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.
Re: Create windows explorer with QListView QTreeView
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.
2 Attachment(s)
Re: Create windows explorer with QListView QTreeView
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
Code:
#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
mainwindow.cpp
Code:
#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));
}
Attachment 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 ???
Attachment 7266
Re: Create windows explorer with QListView QTreeView
Code:
#include <QtGui>
int main(int argc, char *argv[])
{
QFileSystemModel model;
model.setRootPath("");
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.