You are not logged in.

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.

pavlacki

Beginner

  • "pavlacki" started this thread

Posts: 26

Location: Belgium - Bruxelles

Occupation: developer

  • Send private message

1

Monday, December 5th 2005, 7:34pm

set pixmap transparent

Hello

how can I set a image QPixmap transparent?

thanks

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Monday, December 5th 2005, 7:50pm

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.

pavlacki

Beginner

  • "pavlacki" started this thread

Posts: 26

Location: Belgium - Bruxelles

Occupation: developer

  • Send private message

3

Tuesday, December 6th 2005, 10:27am

I done it
QPixmap alpha("image-with-alpha.png");
QPixmap alphacopy = alpha;
alphacopy.setMask(*alphacopy.mask());

but the 2 pixmap are still the same

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


How can I change the mask, in other word how to change the QBitmap and set all the bit to 0.

Thanks

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Tuesday, December 6th 2005, 10:33am

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.


As I said, make a deep copy of the pixmap first.

gadnio

Trainee

  • "gadnio" is male

Posts: 71

Location: Bulgaria

Occupation: C++/Delphi developer

  • Send private message

5

Tuesday, December 6th 2005, 10:56am

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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* XPM */
static char * checkbox_checked_xpm[] = {
"15 15 2 1",
"       c None",
".      c #000000",
"               ",
"               ",
"   .........   ",
"  ..       ..  ",
"  .         ...",
"  .        ....",
"  .      ....  ",
"  .      .. .  ",
"  . ..  ..  .  ",
"  .  .. ..  .  ",
"  .  ....   .  ",
"  ..   .   ..  ",
"   .........   ",
"               ",
"               "};