QImageWriter::supportedMimeTypes() jpeg
-
Hi,
In screenShot example,
http://doc.qt.io/qt-5/qtwidgets-desktop-screenshot-example.htmlvoid Screenshot::saveScreenshot() { const QString format = "png"; QString initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); if (initialPath.isEmpty()) initialPath = QDir::currentPath(); initialPath += tr("/untitled.") + format; QFileDialog fileDialog(this, tr("Save As"), initialPath); fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setDirectory(initialPath); QStringList mimeTypes; foreach (const QByteArray &bf, QImageWriter::supportedMimeTypes()) mimeTypes.append(QLatin1String(bf)); fileDialog.setMimeTypeFilters(mimeTypes); fileDialog.selectMimeTypeFilter("image/" + format); fileDialog.setDefaultSuffix(format); if (fileDialog.exec() != QDialog::Accepted) return; const QString fileName = fileDialog.selectedFiles().first(); if (!originalPixmap.save(fileName)) { QMessageBox::warning(this, tr("Save Error"), tr("The image could not be saved to \"%1\".") .arg(QDir::toNativeSeparators(fileName))); } }
After clicking "Save Screenshot" pushbutton, "Save As"
dialog pops up. In "Files of type" combobox, I see several supported file
formats such as .bmp, .jpeg, .jpg, .png, ...
When I select "PNG image(.png)" comboBox, the "File name" lineEdit shows the file name with the extension changed automatically to myfile.png. but when I select "JPEG image(.jpeg *.jpg *.jpe)", the "File name:" LineEdit shows with the extension changed to myfile.jpeg. I want it to change its extension automatically to myfile.jpg instead of myfile.jpeg.
How can I do this? -
Hi,
Shot in the dark: remove all other extensions from the jpeg entry.
Hope it helps
-
No, when you populate
mimeTypes
, check if jpeg appears in the entry and modify it before adding it tomimeTypes
. -
You're welcome !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)