C++ – How to put an QImage with transparency onto the clipboard for another application to use

cqt

I have a QImage that I would like to put on the clipboard, which I can do just fine. However the transparency is lost when that data is pasted into a non-Qt application. The transparent part just comes out as black. I tried saving the data as a transparent PNG but nothing is usable on the clipboard.

This is what I have so far:

QImage mergedImage = mergeSelectedItems(scene->items());

QMimeData* mimeData = new QMimeData();

QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
mergedImage.save(&buffer, "PNG");
buffer.close();
mimeData->setData("image/png", data);

clipboard->setMimeData( mimeData );

Best Answer

I had the same problem. I replaced

mimeData->setData("image/png", data);

with

mimeData->setData("PNG", data);

It works in MS Office and Gimp, but not in OpenOffice.

Related Topic