Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImageWriter::supportedMimeTypes() jpeg
Forum Updated to NodeBB v4.3 + New Features

QImageWriter::supportedMimeTypes() jpeg

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    Hi,
    In screenShot example,
    http://doc.qt.io/qt-5/qtwidgets-desktop-screenshot-example.html

    void 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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Shot in the dark: remove all other extensions from the jpeg entry.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Shot in the dark: remove all other extensions from the jpeg entry.

        Hope it helps

        S Offline
        S Offline
        samdol
        wrote on last edited by
        #3

        @SGaist
        How could I remove them? Do I have to modify the source code of Qt?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No, when you populate mimeTypes, check if jpeg appears in the entry and modify it before adding it to mimeTypes.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            No, when you populate mimeTypes, check if jpeg appears in the entry and modify it before adding it to mimeTypes.

            S Offline
            S Offline
            samdol
            wrote on last edited by
            #5

            @SGaist
            I tried it. But it did not work. Instead of supportedMimeTypes(), I decided to use supportedImageFormats() though it demands some extra work. Thanks anyway.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved