简体   繁体   中英

Show mp3 files but select folder with QFileDialog

Currently, I can select a folder using QFileDialog 's getExistingDirectory function. 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.

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. Giving a kind of hints only....

On Windows and macOS, this static function will use the native file dialog and not a QFileDialog. However, the native Windows file dialog does not support displaying files in the directory chooser. You need to pass DontUseNativeDialog to display files using a QFileDialog. ( from qfiledialog documentation)

So set the 'QFileDialog::DontUseNativeDialog' option using 'setflags'

Then using file dialog's 'setfilter' set the filter for your MP3 files..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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