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. How to control the quality/filesize of images copied to the clipboard?
Forum Updated to NodeBB v4.3 + New Features

How to control the quality/filesize of images copied to the clipboard?

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 5 Posters 10.8k Views 4 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.
  • SGaistS SGaist

    You can't, QImage is an uncompressed hardware independent representation of the image that allows direct access to pixel data while QPixmap is an off-screen image representation that you can be used as a paint device so it's hardware dependent.

    If you want small images in your PowerPoint document you have to start with the original image and make them lighter.

    btseB Offline
    btseB Offline
    btse
    wrote on last edited by
    #21

    @SGaist said in How to control the quality/filesize of images copied to the clipboard?:

    If you want small images in your PowerPoint document you have to start with the original image and make them lighter.

    Yes, but the question has been, how do I make the original image lighter and reflect this when copied to the clipboard?

    raven-worxR 1 Reply Last reply
    0
    • btseB btse

      @SGaist said in How to control the quality/filesize of images copied to the clipboard?:

      If you want small images in your PowerPoint document you have to start with the original image and make them lighter.

      Yes, but the question has been, how do I make the original image lighter and reflect this when copied to the clipboard?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #22

      @btse
      and what about the way i already suggested?!

          QPixmap pixmap;
          QByteArray bytes;
          QBuffer buffer(&bytes);
          buffer.open(QIODevice::WriteOnly);
          pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter
          buffer.close();
      
          QMimeData *mimeData = new QMimeData;
               mimeData->setData("image/png", bytes);
          QApplication::clipboard()->setMimeData(mimeData);
      

      This should definitely work, even when the your used clipboard inspector doesn't display it correctly.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      btseB 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @btse
        and what about the way i already suggested?!

            QPixmap pixmap;
            QByteArray bytes;
            QBuffer buffer(&bytes);
            buffer.open(QIODevice::WriteOnly);
            pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter
            buffer.close();
        
            QMimeData *mimeData = new QMimeData;
                 mimeData->setData("image/png", bytes);
            QApplication::clipboard()->setMimeData(mimeData);
        

        This should definitely work, even when the your used clipboard inspector doesn't display it correctly.

        btseB Offline
        btseB Offline
        btse
        wrote on last edited by
        #23

        @raven-worx said in How to control the quality/filesize of images copied to the clipboard?:

        @btse
        and what about the way i already suggested?!

            QPixmap pixmap;
            QByteArray bytes;
            QBuffer buffer(&bytes);
            buffer.open(QIODevice::WriteOnly);
            pixmap.save(&buffer, "PNG", 0); // This is where you'd play with the quality parameter
            buffer.close();
        
            QMimeData *mimeData = new QMimeData;
                 mimeData->setData("image/png", bytes);
            QApplication::clipboard()->setMimeData(mimeData);
        

        This should definitely work, even when the your used clipboard inspector doesn't display it correctly.

        It simply doesn't work, not sure what else to tell you. I tried pasting it to many different applications, none of them recognize the clipboard's contents. Have you been able to get this example to work? I've been testing on Mac OS 10.11.6 with Qt 4.8.7.2.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Basilio
          wrote on last edited by
          #24

          Two years too late, but as I was having the exact same issue it might help a lost soul in the future.

          A workaround for this is to save a temporary image and copy to clipboard the url to the file. This is recognized in most software on Mac (PPTX, Keynote included) and should work on Windows.

          void ToClipboard(const QPixmap& pixmap)
          {
              QString filename = "/tmp/screenshot.png";
              pixmap.save(filename);
              QList<QUrl> urls;
              urls << QUrl(filename);
              QMimeData* outputMime = new QMimeData;
              outputMime->setUrls(urls);
              qApp->clipboard()->setMimeData(outputMime);
          }
          

          Take care of the typical caveats when writing to disk from an application, but for most applications that might need this (user-generated, user-controlled operations) this is an ok workaround.

          1 Reply Last reply
          1

          • Login

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