Results 1 to 4 of 4

Thread: Create windows explorer with QListView QTreeView

  1. #1
    Join Date
    Mar 2009
    Location
    Israel
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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.

  3. #3
    Join Date
    Oct 2009
    Location
    Hamburg - Germany
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry 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
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QFileSystemModel>
    6.  
    7. namespace Ui
    8. {
    9. class MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18. ~MainWindow();
    19.  
    20. private slots:
    21. void on_treeView_clicked(const QModelIndex &index);
    22.  
    23. private:
    24. Ui::MainWindow *ui;
    25. QFileSystemModel *drivesModel;
    26. QFileSystemModel *filesModel;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. QString sPath = "C:/";
    11. drivesModel = new QFileSystemModel(this);
    12. drivesModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
    13. drivesModel->setRootPath(sPath);
    14. ui->treeView->setModel(drivesModel);
    15. ui->treeView->hideColumn(1);
    16. ui->treeView->hideColumn(2);
    17. ui->treeView->hideColumn(3);
    18.  
    19. filesModel = new QFileSystemModel(this);
    20. filesModel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    21. filesModel->setRootPath(sPath);
    22. ui->listView->setModel(filesModel);
    23. }
    24.  
    25. MainWindow::~MainWindow()
    26. {
    27. delete ui;
    28. }
    29.  
    30. void MainWindow::on_treeView_clicked(const QModelIndex &index)
    31. {
    32. QString sPath = drivesModel->fileInfo(index).absoluteFilePath();
    33. ui->listView->setRootIndex(filesModel->setRootPath(sPath));
    34. }
    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

  4. #4
    Join Date
    May 2011
    Posts
    46
    Thanks
    5

    Default Re: Create windows explorer with QListView QTreeView

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QFileSystemModel model;
    8. model.setRootPath("");
    9. QTreeView tree;
    10. tree.setModel(&model);
    11.  
    12. // Demonstrating look and feel features
    13. tree.setAnimated(false);
    14. tree.setIndentation(20);
    15. tree.setSortingEnabled(true);
    16.  
    17. tree.setWindowTitle(QObject::tr("Dir View"));
    18. tree.resize(640, 480);
    19. tree.show();
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.

Similar Threads

  1. how to create internet explorer toolbar using Qt?
    By live_07 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2011, 07:28
  2. I want to create a form with QListView
    By xiongxiongchuan in forum Qt Programming
    Replies: 15
    Last Post: 10th June 2010, 05:21
  3. Replies: 1
    Last Post: 15th August 2009, 11:23
  4. Replies: 7
    Last Post: 17th April 2006, 13:57
  5. windows explorer
    By denis in forum Newbie
    Replies: 1
    Last Post: 25th January 2006, 05:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.