PDA

View Full Version : QT 4.2 widget setmask problem



PiXeL16
28th February 2007, 00:48
Hi all,
Hope someone can help.
I develop my application main widget so it have transparent edges, by following the TUX example.
This work perfectly in QT 4.1.
But now i move to QT 4.2 and does not work anymore, all the borders come black, and its look like the widget mask is not been applied.
Any info on this?
What can i do???
Any help will be much appreciated
Thanks
CJC.

Glitch
28th February 2007, 02:40
Can you post some code you are using?

PiXeL16
28th February 2007, 04:09
Sure, this is basically my code.


QPixmap pixmap("transparentImage.png");
QImage image("transparentImage.png");
QBitmap bt();



//Create the mask
image = image.createAlphaMask(Qt::AutoColor);


bt= QBitmap::fromImage(image,Qt::AutoColor);
pixmap.setMask(bt);



//Aply the mask to the widget
_mainWidget->setMask(pixmap.mask());

The result in qt 4.1 is that the mask is applied to the mainwidget and the transparent pixel in the image come clipped.
The result in qt 4.2 is that the transparent pixels in the image are black, and looks like the mask is not been applied

Any help plz :eek:
THanks
CJC

PiXeL16
28th February 2007, 18:24
Any help on this plz :crying:

jpn
28th February 2007, 19:21
I thought it was something as simple as this when the image had transparent edges:


QPixmap pixmap("transparentImage.png");
_mainWidget->setMask(pixmap.mask());

PiXeL16
28th February 2007, 21:19
Me too, but it didnt work.
So I try to do it like the tux example and it work very good in qt 4.1 but in qt 4.2 now dont work.
Any more help on this?
Maybe someone has a workarround or and example that work in qt 4.2?
Thanks
CJC! :crying:

fullmetalcoder
28th February 2007, 21:46
Me too, but it didnt work.
So I try to do it like the tux example and it work very good in qt 4.1 but in qt 4.2 now dont work.
Any more help on this?
Maybe someone has a workarround or and example that work in qt 4.2?

Have you checked the Tux example in Qt 4.2???

PiXeL16
1st March 2007, 05:41
The problem is that the TUX example is not included.
Even in qt 4.1 it was not included. I need to work with the old example i think from qt 3 and change all the not working and old functions.
Any way, someone has and example of this or maybe some workaround to make this work?
Please, any help will be much appreciated.
Thanks
CJC

jpn
1st March 2007, 09:37
I'm using Qt 4.2.2 on X11 and it works for me the simple way I described.. Doesn't the attached example work for you? ;)

PiXeL16
1st March 2007, 17:44
Thanks,
Yeah thats the effect that i want to give.
Maybe is because im using a dialog? and you are using a label?
Or also, im using a qpainter to create the image. maybe something change from qt 4.1 to qt 4.2 and the qpainter draw images does not create transparent parts?
:confused: :confused: :confused: :confused:
Thanks
CJC

jpn
1st March 2007, 18:08
Maybe is because im using a dialog? and you are using a label?
That should not have effect of any kind. Both are QWidgets.



Or also, im using a qpainter to create the image. maybe something change from qt 4.1 to qt 4.2 and the qpainter draw images does not create transparent parts?

Try filling the image with a transparent color before painting the shape.

Glitch
1st March 2007, 21:06
Sure, this is basically my code.


QPixmap pixmap("transparentImage.png");
QImage image("transparentImage.png");
QBitmap bt();



//Create the mask
image = image.createAlphaMask(Qt::AutoColor);


bt= QBitmap::fromImage(image,Qt::AutoColor);
pixmap.setMask(bt);



//Aply the mask to the widget
_mainWidget->setMask(pixmap.mask());

The result in qt 4.1 is that the mask is applied to the mainwidget and the transparent pixel in the image come clipped.
The result in qt 4.2 is that the transparent pixels in the image are black, and looks like the mask is not been applied


This looks reasonable. Have you thought that maybe your app isn't finding transparentImage.png. I notice a relative path here. Try using the qt resource system to embed your images into the executable.

--Justin

PiXeL16
2nd March 2007, 01:13
Hi thanks for the reply.
No, that was an example. Im using a qrc resource file, and the app is finding the image correctly.
Also, im using a qpainter to create a big image from small image. The qpainter default color is transparent, so i dont have to do that according to QT.
Anyway, i try setting a transparent color with no luck.
Anything that i could be missing here?

jpn
2nd March 2007, 01:26
Also, im using a qpainter to create a big image from small image.
How about scaling (http://doc.trolltech.com/4.2/qpixmap.html#scaled)?


The qpainter default color is transparent, so i dont have to do that according to QT.
Yes, but QPixmap might not be. As you said, a new QPixmap is constructed. What I actually meant was filling that pixmap with transparent color.

wysota
2nd March 2007, 01:28
You could be using some window flags that cause the problem. Could we see the _mainWidget constructor and the way you call it?

PiXeL16
2nd March 2007, 08:08
Hi, thanks for the reply
What i mean by creating an image with small images is that i'm creating and pixmap using small various pixmap. So i cant use scaling.
I'm going to try your idea of filling the pixmap first with transparent color. Maybe that work.
Also, about the flags, i'm just basically using a frameless flag. like this.



Qt::WindowFlags flags = 0;
flags = Qt::FramelessWindowHint;
_mainWidget->setWindowFlags(flags);


Could something change in the way qt manage transparent colors from qt 4.1 to 4.2?
Thanks
Any help will be much appreciated
CJC

PiXeL16
2nd March 2007, 08:09
I forget, im calling it with the show function
like this


_mainWidget->show();

Thanks
CJC