// 初始化图片文件对话框
static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMode acceptMode)
{
static bool firstDialog = true;
//设置文件对话框的打开目录为系统图片标准位置
if (firstDialog) {
firstDialog = false;
const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
dialog.setDirectory(picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.last());
}
QStringList mimeTypeFilters;
const QByteArrayList supportedMimeTypes = acceptMode == QFileDialog::AcceptOpen
? QImageReader::supportedMimeTypes() : QImageWriter::supportedMimeTypes();
for (const QByteArray &mimeTypeName : supportedMimeTypes)
mimeTypeFilters << mimeTypeName;
//mimeTypeFilters.append(mimeTypeName);
mimeTypeFilters.sort();
dialog.setMimeTypeFilters(mimeTypeFilters);
dialog.selectMimeTypeFilter("image/jpeg");
dialog.setAcceptMode(acceptMode);
if (acceptMode == QFileDialog::AcceptSave)
dialog.setDefaultSuffix("jpg");//设置默认文件后缀
}