Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Suggestions/Ideas about a file browser

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

    Thumbs up Suggestions/Ideas about a file browser

    Hi all, one of the options in my application is to browse all the images in a specified directory and move them to other directories (that could not exist). I have some ideas but I will be thankfully if you give me some other ideas before I program it. The only restriction is that the re-ubication of the image files has to be in a simple way like a drag-and-drop. I have thought in having a QListWidget with a thumbnailing of all the images in the "source" directory. This directory is inserted in a QLineEdit or chosen using a button connected to QFileDialog::getExistingDirectory. For the destination folder I have thought in having the same widgets: a list view, a line edit and the button. So the user only should has to select the destination folder and drag and drop all the files from the source directory to the destination. Another posssiblity could be in replacing the QListWidget in the destination for a tree showing the file system giving the possiblity to create new directories and drag the list widget items of the source directory to an entry of this tree. I don't know if this could be possible. I also have thought in having another tree in the source folder too... Anyway, what do you suggest me?

    Thanks.

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

    Default Re: Suggestions/Ideas about a file browser

    Hi again, I've thought in another solution: having a QDirModel with a tree structure showing the dirs of the file system in one place and on the other place a QListWidget that will contains the thumbnailed images for the current/selected directory in the dir model. I have some questions about it:
    1) To copy image files between directories, is possible to drag QListWidgetItems from the list widget to drop them in a directory entry of the dir model?
    2) Is possible to show a menu when the user clicks with the right button of the mouse an entry of the dir model? This menu will show the actions to do with a directory: rename it, delete it, create sub-directory, view the images in the list widget, ...

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

    Default Re: Suggestions/Ideas about a file browser

    I'd say, forget about the QListWidget and use a QDirModel+QListView instead..
    J-P Nurmi

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

    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.

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

    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

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

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

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

    Default Re: Suggestions/Ideas about a file browser

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

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

    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

  9. #8
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Suggestions/Ideas about a file browser

    You can further improve the above implementation by setting the file icon provider for your list to show the thumbnails for your images in the list. Refer to the QFileIconProvider class in QT documentation. Implementing the icon provider for the thumbnails will look like this:

    Qt Code:
    1. QIcon MyIconProvider::icon ( const QFileInfo & info ) const
    2. {
    3. //Initializing the pixmap from file
    4. QPixmap pixmap( info.filePath() );
    5. //Processing the valid pixmap
    6. if ( !pixmap.isNull() )
    7. {
    8. //Resizing the pixmap to the required thumbnail size
    9. pixmap = pixmap.scaled( mySize );
    10. return QIcon( pixmap );
    11. }
    12. else return QIcon();
    13. }
    To copy to clipboard, switch view to plain text mode 

    You'll have to set-up the icon size of your list view to mySize by calling the setIconSize() method and set the icon provider for your QDirModel. This implementation can be further improved, but this is something to start with.

  10. The following 2 users say thank you to Lemming for this useful post:

    babu198649 (8th November 2007), SkripT (4th April 2006)

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

    Default Re: Suggestions/Ideas about a file browser

    Do you know if there's any documentation that shows detailed some examples on how to work with a QDirModel and its communication with a QListView or how to create a complete file manager with it?

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

    Default Re: Suggestions/Ideas about a file browser

    Not that I know. The only example of QDirModel usage provided with Qt is the Dir View example.
    Neither does the QDirModel documentation provide much of example usage, but the common model/view programming concept applies here too..
    J-P Nurmi

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

    SkripT (4th April 2006)

  14. #11
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Suggestions/Ideas about a file browser

    From my experience of implementing the full-scale file browser, QT documentation is sufficient to get things working if you're familiar with Model/View architecture. If not, you probably shold start with reading the Model/View tutorial that is supplied with QT.

    BTW, there was a nice file browser example in QT3 solutions. Unfortunately it is not yet ported to QT4, causing a lot of troubles for those who need a file browser in their application.

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

    SkripT (4th April 2006)

  16. #12
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suggestions/Ideas about a file browser

    The simple file browser provided by jpn is a great example..but it does not have the drop facility within the listview itself...(both, on the left as well as right col. of the splitter)...ummm how would you achieve this!!

    Nupul

  17. #13
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Suggestions/Ideas about a file browser

    You'll have to subclass from QListView and overload the dropEvent

    Qt Code:
    1. //Enabling the drops for the list viewport
    2. list->viewport()->setAcceptDrops( true );
    3.  
    4. void FileExplorerList::dropEvent( QDropEvent *event )
    5. {
    6. [INDENT]if ( event->mimeData()->hasUrls() )
    7. {
    8. [INDENT]
    9. //Getting the dir model of the list
    10. QDirModel *dirModel = qobject_cast<QDirModel*>( list->model() );
    11. //Dropping the mime data
    12. dirModel->dropMimeData( event->mimeData(), event->proposedAction(), parentIndex );
    13. //Note: it's up to you to get the parent index for the drop operation[/INDENT]
    14. }[/INDENT]}
    To copy to clipboard, switch view to plain text mode 

    This should work fine. Actually, there is QDirModel::setReadOnly( bool ) method as well. I'm not sure about it, but setting it to on might possible enable the default drop functionality for the dir model.

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

    nupul (5th April 2006)

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

    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.

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

    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

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

    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.

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

    jpn (4th November 2007)

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

    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

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

    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

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

    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?

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

    Default Re: Suggestions/Ideas about a file browser

    J-P Nurmi

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.