Results 1 to 5 of 5

Thread: How to make a file dialog with dirs only, multiselection and network places?

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Question How to make a file dialog with dirs only, multiselection and network places?

    Hey guys

    I need to create a file dialog where one can pick directories only with multiselection and there must be network places.

    I cannot do all this stuff using the standard possibilities of QFileDialog. The closest method to my problem is QFileDialog::getExistingDirectory (there are only directories, multiselection and network places -- all I need) but it has a bug -- when one selects several folders the method returns "" (an empty string). I tried to rewrite getExistingDirectory in QFileDialog.cpp but in that case I have to rebuild qt dll (QtCore.dll as far as I remember). Maybe there is an easier solution?

    How can I solve my problem? I need some help, please.

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: How to make a file dialog with dirs only, multiselection and network places?

    Use QDir also, for more information go here,
    http://www.developer.nokia.com/Commu...leDialog_in_Qt
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: How to make a file dialog with dirs only, multiselection and network places?

    Thank you but I need another thing. I need a native standard file dialog where one can choose several folders (multiselection). So in other words I need a kind of re-implemented QFileDialog::getExistingDirectory that returns QStringList instead of QString. I want to get a list of selected folders. So I need my file dialog to look like QFileDialog::getOpenFileNames but for folders, not for files.

  4. #4
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make a file dialog with dirs only, multiselection and network places?

    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 


    The following is the codes that you could try(The original link is http://www.qtcentre.org/threads/3422...108#post220108):

    Qt Code:
    1. QFileDialog* _f_dlg = new QFileDialog(this);
    2. _f_dlg->setFileMode(QFileDialog::Directory);
    3. _f_dlg->setOption(QFileDialog::DontUseNativeDialog, true);
    4.  
    5. // Try to select multiple files and directories at the same time in QFileDialog
    6. QListView *l = _f_dlg->findChild<QListView*>("listView");
    7. if (l) {
    8. l->setSelectionMode(QAbstractItemView::MultiSelection);
    9. }
    10. QTreeView *t = _f_dlg->findChild<QTreeView*>();
    11. if (t) {
    12. t->setSelectionMode(QAbstractItemView::MultiSelection);
    13. }
    14.  
    15. int nMode = _f_dlg->exec();
    16. QStringList _fnames = _f_dlg->selectedFiles();
    To copy to clipboard, switch view to plain text mode 
    Last edited by sonulohani; 1st August 2012 at 11:05.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  5. The following user says thank you to sonulohani for this useful post:

    tehman (1st August 2012)

  6. #5
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: How to make a file dialog with dirs only, multiselection and network places?

    Thank you again, I have tried your code. Only one problem -- the dialog is not native and there are no network places. I have read another discussion board and one said there that only static methods of QFileDialog offered native windows, windows that I need. So I am afraid there is no opportunity to solve my problem completely using QFileDialog. Maybe I should change Qt's source code and build another QtCore.dll to use reimplemented static methods.

Similar Threads

  1. Replies: 10
    Last Post: 28th January 2011, 09:50
  2. Replies: 0
    Last Post: 15th November 2009, 10:40
  3. My Network Places in QFileDialog
    By AlHadr in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 16:38
  4. File Dialog / Network Protocols in QT4
    By themolecule in forum Qt Programming
    Replies: 6
    Last Post: 10th September 2007, 08:40
  5. Replies: 4
    Last Post: 12th April 2007, 20:52

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.