PDA

View Full Version : How to use QFileDialog to list files but not directories ?



xlttap
17th August 2010, 06:40
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 ?

Ginsengelf
17th August 2010, 06:55
Hi, maybe QFileDialog::setFileMode() helps.

Ginsengelf

xlttap
17th August 2010, 07:24
Hi, maybe QFileDialog::setFileMode() helps.

Ginsengelf

I have tried,but it still not works.

franz
17th August 2010, 07:35
Why would you want to deny people the ability to browse for their files?

xlttap
18th August 2010, 04:23
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();
// ... ...