Results 1 to 5 of 5

Thread: QFileDialog select multiple directories

  1. #1
    Join Date
    Aug 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFileDialog select multiple directories

    Using a QFileDialog, I can allow the user to select one or more files, or to select one directory. Is there any way to allow selecting multiple directories?

    I have found this FAQ on the qt-site, but the code there doesn't work (even after fixing the typos).

    Any ideas?

    thanks,
    bepaald

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog select multiple directories

    It seems that the QFileDialog won't do it out of the box. My solution would be to build a new directory picker dialog for your application, supporting multiple directories. By using a QFileSystemModel, you don't have to worry about traversing the file system.

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog select multiple directories

    My guess would be that the solution posted in the FAQ can't work with the OS-native filedialogs, which are used by default.
    The native dialog won't have a QListWidget etc..

    Try opening a qt one.

    Qt Code:
    1. filedialog.setOption(QFileDialog::DontUseNativeDialog,true);
    To copy to clipboard, switch view to plain text mode 

    Joh
    Last edited by JohannesMunk; 16th September 2010 at 20:45.

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog select multiple directories

    I just checked; multiselection works:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. w.setFileMode(QFileDialog::DirectoryOnly);
    7. w.setOption(QFileDialog::DontUseNativeDialog,true);
    8. QListView *l = w.findChild<QListView*>("listView");
    9. if (l) {
    10. l->setSelectionMode(QAbstractItemView::MultiSelection);
    11. }
    12. QTreeView *t = w.findChild<QTreeView*>();
    13. if (t) {
    14. t->setSelectionMode(QAbstractItemView::MultiSelection);
    15. }
    16. return w.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    It works no matter what I set the DontUseNativeDialog to. I can't seem to get the native dialog going! Strange!

    I'm on Win7. Qt4.7. Mingw.

    Joh

  5. The following 2 users say thank you to JohannesMunk for this useful post:

    ijab (15th May 2012), sedi (13th April 2013)

  6. #5
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog select multiple directories

    The following codes are a good solution to select multiple directories and files in the same QFileDialog. Thanks!

    Quote Originally Posted by JohannesMunk View Post
    I just checked; multiselection works:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. w.setFileMode(QFileDialog::DirectoryOnly);
    7. w.setOption(QFileDialog::DontUseNativeDialog,true);
    8. QListView *l = w.findChild<QListView*>("listView");
    9. if (l) {
    10. l->setSelectionMode(QAbstractItemView::MultiSelection);
    11. }
    12. QTreeView *t = w.findChild<QTreeView*>();
    13. if (t) {
    14. t->setSelectionMode(QAbstractItemView::MultiSelection);
    15. }
    16. return w.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    It works no matter what I set the DontUseNativeDialog to. I can't seem to get the native dialog going! Strange!

    I'm on Win7. Qt4.7. Mingw.

    Joh

Similar Threads

  1. Replies: 4
    Last Post: 18th August 2010, 04:23
  2. Select multiple curves
    By aimsc in forum Qwt
    Replies: 2
    Last Post: 30th October 2009, 10:45
  3. Select multiple files from QFileDialog
    By jiveaxe in forum Qt Programming
    Replies: 6
    Last Post: 16th February 2009, 14:57
  4. QTableWidget - Select multiple rows.
    By wally in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2008, 17:15
  5. How to create directories??
    By paranoid_android in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2006, 16:28

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.