简体   繁体   English

显示mp3文件,但使用QFileDialog选择文件夹

[英]Show mp3 files but select folder with QFileDialog

Currently, I can select a folder using QFileDialog 's getExistingDirectory function. 当前,我可以使用QFileDialoggetExistingDirectory函数选择一个文件夹。 Even thought I managed to let the dialog show the files as well, I would like to filter them, ie display only folders and *.mp3 files. 甚至以为我也设法让对话框也显示文件,我想过滤它们,即只显示文件夹和*.mp3文件。

QString folder = QFileDialog::getExistingDirectory(this, "test", "", QFileDialog::ReadOnly);

Is this possible without creating a custom dialog? 是否可以在不创建自定义对话框的情况下实现?

QFileDialog d(this);
d.setFileMode(QFileDialog::Directory);
d.setNameFilter("*.mp3");
if (d.exec())
  qDebug () << d.selectedFiles();

I am on mobile rt now. 我现在在移动rt上。 Giving a kind of hints only.... 仅给出一种提示。

On Windows and macOS, this static function will use the native file dialog and not a QFileDialog. 在Windows和macOS上,此静态函数将使用本机文件对话框而不是QFileDialog。 However, the native Windows file dialog does not support displaying files in the directory chooser. 但是,本机Windows文件对话框不支持在目录选择器中显示文件。 You need to pass DontUseNativeDialog to display files using a QFileDialog. 您需要传递DontUseNativeDialog来使用QFileDialog显示文件。 ( from qfiledialog documentation) (来自qfiledialog文档)

So set the 'QFileDialog::DontUseNativeDialog' option using 'setflags' 因此,使用“ setflags”设置“ QFileDialog :: DontUseNativeDialog”选项

Then using file dialog's 'setfilter' set the filter for your MP3 files.. 然后使用文件对话框的“ setfilter”为您的MP3文件设置过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM