Results 1 to 20 of 32

Thread: Suggestions/Ideas about a file browser

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by jpn
    I'd say, forget about the QListWidget and use a QDirModel+QListView instead..
    jpn I appreciate your suggestion but can you give me some reasons and how you think that I should use the list view?
    Last edited by SkripT; 4th April 2006 at 12:15.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    Because it's this simple:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. // a "file manager" at simplest :)
    8. QSplitter* splitter = new QSplitter;
    9. QDirModel* model = new QDirModel;
    10. QTreeView* tree = new QTreeView(splitter);
    11. tree->setModel(model);
    12. QListView* list = new QListView(splitter);
    13. list->setModel(model);
    14. list->setDragEnabled(true);
    15. splitter->show();
    16.  
    17. // tree navigation by click
    18. QObject::connect(tree, SIGNAL(clicked(const QModelIndex&)),
    19. list, SLOT(setRootIndex(const QModelIndex&)));
    20. // list navigation by dbl click
    21. QObject::connect(list, SIGNAL(doubleClicked(const QModelIndex&)),
    22. list, SLOT(setRootIndex(const QModelIndex&)));
    23. // update tree upon list change
    24. QObject::connect(list, SIGNAL(doubleClicked(const QModelIndex&)),
    25. tree, SLOT(setCurrentIndex(const QModelIndex&)));
    26.  
    27. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Notice the amount of code ..with this, you can already drag'n drop a file from the list view to e.g. desktop..
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    hvw59601 (4th November 2007), SkripT (4th April 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Cool jpn thanks , where have you get this example? Is it from your creation?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    No problem. Yep, I did it myself..
    It's not a complete solution, just a small example demonstrating the power of QDirModel
    J-P Nurmi

  6. #5
    Join Date
    Feb 2007
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by jpn View Post
    Because it's this simple:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. // a "file manager" at simplest :)
    8. QSplitter* splitter = new QSplitter;
    9. QDirModel* model = new QDirModel;
    10. QTreeView* tree = new QTreeView(splitter);
    11. tree->setModel(model);
    12. QListView* list = new QListView(splitter);
    13. list->setModel(model);
    14. list->setDragEnabled(true);
    15. splitter->show();
    16.  
    17. // tree navigation by click
    18. QObject::connect(tree, SIGNAL(clicked(const QModelIndex&)),
    19. list, SLOT(setRootIndex(const QModelIndex&)));
    20. // list navigation by dbl click
    21. QObject::connect(list, SIGNAL(doubleClicked(const QModelIndex&)),
    22. list, SLOT(setRootIndex(const QModelIndex&)));
    23. // update tree upon list change
    24. QObject::connect(list, SIGNAL(doubleClicked(const QModelIndex&)),
    25. tree, SLOT(setCurrentIndex(const QModelIndex&)));
    26.  
    27. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Notice the amount of code ..with this, you can already drag'n drop a file from the list view to e.g. desktop..
    Nice... is there any way you can go back to the parent of the "current" modelindex? Or does setRootIndex() overwrite everything "above" the defined index?

    I am using a QTreeView with
    view->setRootIsDecorated(false);
    view->setItemsExpandable(false);

    So I can only see the top level list.
    Last edited by invictus; 4th November 2007 at 14:38.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    You can get the parent via QModelIndex::parent(). If you want to provide a button with "go one level up" -functionality, the slot connected to button's SIGNAL(clicked()) would do roughly:
    Qt Code:
    1. QModelIndex parent = view->rootIndex().parent();
    2. view->setRootIndex(parent);
    3. button->setEnabled(parent.parent().isValid());
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 4th November 2007 at 16:12. Reason: spelling error
    J-P Nurmi

  8. #7
    Join Date
    Feb 2007
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by jpn View Post
    You can get the parent via QModelIndex::parent(). If you want to provide a button with "go one level up" -functionality, the slot connected to button's SIGNAL(clicked()) would do roughly:
    Qt Code:
    1. QModelIndex parent = view->currentIndex().parent();
    2. view->setCurrentIndex(parent);
    3. button->setEnabled(parent.parent().isValid());
    To copy to clipboard, switch view to plain text mode 
    This seem to work fine...until I select an item. Then the up-action will no longer work for some reason. Although I am using setRootIndex instead of setCurrentIndex in order to show a flat structure instead of a tree.

  9. The following user says thank you to invictus for this useful post:

    jpn (4th November 2007)

  10. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by invictus View Post
    This seem to work fine...until I select an item. Then the up-action will no longer work for some reason. Although I am using setRootIndex instead of setCurrentIndex in order to show a flat structure instead of a tree.
    Oops, sorry. Those should've been rootIndex() and setRootIndex(). Thanks for pointing it out. I have corrected it to my previous post..
    J-P Nurmi

  11. #9
    Join Date
    Feb 2007
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by jpn View Post
    Oops, sorry. Those should've been rootIndex() and setRootIndex(). Thanks for pointing it out. I have corrected it to my previous post..
    Yeah, but thats when it is not working, unfortunately

  12. #10
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 11 Times in 8 Posts

    Default Re: Suggestions/Ideas about a file browser

    hello all,
    and what about providing custom class inherited from QFileIconProvider (QDirModel::setIconProvider()) that generates thumbnails? My app generates them in separate thread & stores thumbnails in xmlfile in each directory it works great, maybe with similar ithumbsProvider you could have only one QTreeView with thumbnails inside & drag&drop functionalities?

  13. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    J-P Nurmi

  14. #12
    Join Date
    Feb 2007
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by jpn View Post
    Nice example. Thanks.

    But one question. When you doubleclick the treeview it will enter the clicked item...but if the item selected isnt the first column it will not enter the correct directory. Any thoughts on that?

  15. The following user says thank you to invictus for this useful post:

    jpn (6th November 2007)

  16. #13
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 11 Times in 8 Posts

    Default Re: Suggestions/Ideas about a file browser

    connect clicked(const QModelIndex &) or doubleClicked(const QModelIndex &) signal to slot that setRootIndex ( const QModelIndex & ) for index in first column & the same row as passed in signal...

  17. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Suggestions/Ideas about a file browser

    Quote Originally Posted by invictus View Post
    But one question. When you doubleclick the treeview it will enter the clicked item...but if the item selected isnt the first column it will not enter the correct directory. Any thoughts on that?
    Thanks for the bug report. It's fixed now.
    J-P Nurmi

  18. The following user says thank you to jpn for this useful post:

    invictus (7th November 2007)

  19. #15
    Join Date
    Feb 2007
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: Suggestions/Ideas about a file browser

    Speaking of problems...

    This is my goTo slot (much like your setRootIndex):

    void goTo(const QModelIndex &dir)
    {
    if(dirModel->isDir(dir))
    {
    dirView->setRootIndex(dir);
    addressField->setText(dirModel->filePath(dir));
    upAction->setEnabled(dir.isValid());
    }
    }
    dirView is a QTreeView. The problem is that when the up method is run (which run goTo() with the parent() of the dirView rootIndex like in your example) the program just quits/crashes. If I comment the if(dirView->isDir()) line it works.
    Last edited by invictus; 7th November 2007 at 22:10.

  20. #16
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Suggestions/Ideas about a file browser

    hello.// how an i load the files from the file list so that i an get its directory to load the file itself to transfer it to another device..thanks!

  21. #17
    Join Date
    Dec 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: Suggestions/Ideas about a file browser

    Hi I'm doing that thing with the contents of clipboard.. ( a simple enumeration )

    const QMimeData *mime = QApplication::clipboard()->mimeData();
    if (mime && mime->hasUrls()) {
    QStringList fileList;
    foreach(QUrl url, mime->urls())
    fileList.append(url.toLocalFile());
    ........

    But If clipboard was filled by a windows application I can't know if I I need to copy or cut ..... do you know a trick ????

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. Adding property editor file browser popup...
    By thawkins in forum Qt Tools
    Replies: 1
    Last Post: 25th April 2007, 23:03
  4. Replies: 11
    Last Post: 4th July 2006, 15:09
  5. Opening swf file in the default browser
    By munna in forum Qt Programming
    Replies: 16
    Last Post: 5th May 2006, 09:33

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
  •  
Qt is a trademark of The Qt Company.