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. Copying PNG with alpha channel to the clipboard is not working on windows. How can I fix this?
Forum Update on Monday, May 27th 2025

Copying PNG with alpha channel to the clipboard is not working on windows. How can I fix this?

Scheduled Pinned Locked Moved Unsolved General and Desktop
clipboardpngcopytransparencyalpha channel
1 Posts 1 Posters 522 Views
  • 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.
  • D Offline
    D Offline
    derekleesoft
    wrote on last edited by derekleesoft
    #1

    This is my code.

    QImage image= ToTransparent(xxx); //result is transparent image, don't mind this.
    QByteArray imageArray;
    QBuffer buffer(&imageArray);
    buffer.open(QIODevice::WriteOnly);
    image.save(&buffer, "png", 100);
    buffer.close();
    
    QMimeData* mimedata = new QMimeData();
    mimedata->setData("png", imageArray);
    qApp->clipboard()->setMimeData(mimedata);
    

    On windows, when I use qApp->clipboard()->setMimeData(mimedata);, It can be copied to a few applications like Microsoft Office programs but it doesn't work everywhere like Paint, Photoshop, or whatever.
    And I tried to use qApp->clipboard()->setImage(image); and it works everywhere but It loses transparency and the image is always opaque.

    So I was tried to copy the PNG data to the clipboard using Native Libraries of User32.dll or Kernel32.dll but no luck so far.
    Is there any way I can do this with Qt or Native Library on windows?

    Thanks,

    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