PDA

View Full Version : Custom Shape Widget (resize)



PiXeL16
10th February 2007, 06:10
Hi, I try looking into the forum to see if this have been post before. But could not found any.
I needed to create a custom shape widget just like the tux example that come with qt.
I accomplish that.
Now I need to add resize functionality to the widget. I am lost here. How can I maintain the shape of mask that is set by the image when the user resize the widget?
My image has a particular rouded in the edge shape, so i would need to add the resize functionality, and that when the user resize the widget this shape maintain even if the user resize the widget a lot.
Something like MSN messenger on windows.
Does some one have some kind of code the resembles this functionality. Or some examples?
Please, any kind of help in this will be much appreciated
Thanks in advance
CJC

wysota
10th February 2007, 13:39
I guess it depends on the contents of your widget. Assuming it is an image, you can scale the image and convert it into a mask which you can then apply. If it's not an image but a set of widgets, you can probably get a list of regions and paint the mask according to those regions. As a last resort you can redirect painting of your widget to some pixmap and then use the pixmap as a mask (provided that it'll keep its transparent background, but it depends on the widget itself).

PiXeL16
10th February 2007, 18:48
Hi!
Thanks for the reply.
Do you think thats that the best way?
By Scaling the image, wont this loose a lot of resolution, and make the mask look bad?
Isn't there a way to resize the mask when i need it, but that its maintain the same shape of polygon give it by the image? Something just like changing the hight and weight values of the mask?
What could be the best way to accomplish what it need?
Thanks in advance
CJC

wysota
10th February 2007, 23:47
By Scaling the image, wont this loose a lot of resolution, and make the mask look bad?
Maybe I was a bit unclear... If your widget is a label that shows some kind of image and when a resize happens the widget is resized as well, then you can simply convert that resized widget to a mask which can be directly applied on the widget.


Isn't there a way to resize the mask when i need it, but that its maintain the same shape of polygon give it by the image? Something just like changing the hight and weight values of the mask?
If the mask (image) is a vector then you can simply scale.

PiXeL16
11th February 2007, 07:48
Hi, Thanks for the reply.
Well yeah, my widget is not a label, is a qmainwindow that i use to show my application, just like the Tux Example.
I try some solutions but could only get the the result that i wanted by scaling the image.
It loose some resolutions when its very big and the mask looks kind of weird. But at least it work.
If someone has a better way of doing this please let me know
Thanks again
CJC

wysota
11th February 2007, 12:30
Did you try the solution with fetching rectangles of all child windows and using them to draw the mask?

PiXeL16
12th February 2007, 03:19
Yes, but that wont give me the custom shape given by the alphas of the image, it will just return the actual size all the child's, wish are square.
So I need to do this with and image. Do someone know if support for svg images is good with qt?
Could I use svg images just like regular pixmaps?
Thanks
CJC.

wysota
12th February 2007, 08:00
Yes, but that wont give me the custom shape given by the alphas of the image, it will just return the actual size all the child's, wish are square.
But if you are using images, then there shouldn't be any problem... Just make sure you create the mask from the image you will actually display (so don't scale twice - once for the image itself and once for the mask - use the already scaled image). I think there are examples on the forum how to do that. Could you show the actual code which doesn't work for you?


So I need to do this with and image. Do someone know if support for svg images is good with qt?
Depends what you mean by "good" :)


Could I use svg images just like regular pixmaps?

No, these are not pixmaps. You'd have to do a conversion first.