Results 1 to 5 of 5

Thread: How to use QFileDialog to list files but not directories ?

  1. #1
    Join Date
    Mar 2009
    Location
    Beijing
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to use QFileDialog to list files but not directories ?

    I want to show all the files in the QFileDialog and hide the directories of a certain directory,while the QFileDialog provides ShowDirsOnly Options without ShowFilesOnly.
    How can I resolve this issue ?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use QFileDialog to list files but not directories ?

    Hi, maybe QFileDialog::setFileMode() helps.

    Ginsengelf
    Last edited by Ginsengelf; 17th August 2010 at 06:57. Reason: updated contents

  3. #3
    Join Date
    Mar 2009
    Location
    Beijing
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use QFileDialog to list files but not directories ?

    Quote Originally Posted by Ginsengelf View Post
    Hi, maybe QFileDialog::setFileMode() helps.

    Ginsengelf
    I have tried,but it still not works.

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QFileDialog to list files but not directories ?

    Why would you want to deny people the ability to browse for their files?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Mar 2009
    Location
    Beijing
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: How to use QFileDialog to list files but not directories ?

    I have solved this issue,using a QFileDialog object instead of QFileDialog static function getOpenFileName().
    Following:
    QFileDialog dialog;
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setDirectory("/home/user1");
    dialog.setFilter(QDir::Files);
    dialog.setWindowTitle("Open File");
    dialog.setNameFilter("Images(*.jpg *.gif *.bmp)");
    dialog.exec();
    QString file = dialog.selectedFiles().first();
    // ... ...

Similar Threads

  1. Searching files from directories & its subdirectories
    By ashukla in forum Qt Programming
    Replies: 4
    Last Post: 12th April 2014, 12:57
  2. Replies: 9
    Last Post: 28th April 2010, 09:18
  3. QFileDialog filename list order
    By joelthelion in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 14:58
  4. QFileDialog hidden files
    By blukske in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2007, 02:11
  5. how to list out all files in a dir and sub dir
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2006, 14:57

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.