Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.

set pixmap transparent

RE: set pixmap transparent

Quoted

From Qt docs:
void QPixmap::setMask ( const QBitmap & newmask )
Sets a mask bitmap.
The newmask bitmap defines the clip mask for this pixmap. Every pixel in newmask corresponds to a pixel in this pixmap. Pixel value 1 means opaque and pixel value 0 means transparent. The mask must have the same size as this pixmap.
Warning: Setting the mask on a pixmap will cause any alpha channel data to be cleared. For example:
QPixmap alpha("image-with-alpha.png");
QPixmap alphacopy = alpha;
alphacopy.setMask(*alphacopy.mask());
Now, alpha and alphacopy are visually different.
Setting a null mask resets the mask.
See also mask(), createHeuristicMask(), and QBitmap.

If you want semi-transparent parts, you will have to change the alpha channel.

Quoted

Originally posted by pavlacki
QPixmap alphacopy = alpha;

Pixmaps are shared, so you're not making a copy of the pixmap here but only a copy of a reference to the same pixmap (I think it is called a shallow copy), so by changing one of the objects, the other reflects the same changes, so both objects will always be identical.

Quoted

alphacopy.setMask(*alphacopy.mask());

Are you setting a mask to an already existing one?

Quoted

the mask of the pixmap alpha is the same of alphacopy so there is no difference between alpha and alphacopy.

RE: set pixmap transparent

Basically, all you need to make a XPM image transparent, is to open it inside a text editor and look which is the background color character. Once you have found it, set it to "None" and all will be happy.
Example:
checkbox_checked.xpm