QFileDialog : how to set option to show content of folder in getExistingDirectory()

不羁的心 提交于 2019-12-11 01:29:51

问题


I am using QFileDialog as

filename = QFileDialog::getExistingDirectory(this,"Select Image File: ",dataDir,0);

I want that I can check files inside folder before selecting it. function getExistingDirectory() is setting QFileDialog::ShowDirsOnly as a default option. I checked in docs there is no any option that do opposite of this. So I set last parameter 0. But now it is not using native dialog. I want to use native dialog with this. I have no clue how to do this cause no flag found in options for UseNativeDialog. Please help.


回答1:


Try creating the file dialog on your own, something like:

QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setViewMode(QFileDialog::Detail);
dialog.setDirectory(datadir);
dialog.exec();



回答2:


The code by Sebastian should create a native dialog, unless you make a line such as:

dialog.setOption(QFileDialog::DontUseNativeDialog, true);

However, I have not been able to get this working under Windows, even though the documentation says that the QFileDialog::Directory option should display files by default. Not only that, but doing:

qDebug() << dir_selector.testOption(QFileDialog::ShowDirsOnly);

displays false on my system, indicating that there is probably a bug somewhere.



来源:https://stackoverflow.com/questions/19108339/qfiledialog-how-to-set-option-to-show-content-of-folder-in-getexistingdirector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!