PDA

View Full Version : How to draw soft shadow with QPainter?



troorl_ua
21st April 2007, 19:45
Hi
I need to draw something like this (see picture). I don't know, what to make good use - blured lines or gradient or something else :confused:
Please, help me

marcel
21st April 2007, 20:08
The easiest way would be to use a linear gradients in combination with painter opacity for the shadow edges.

You could look at the Gradients example in the Qt Demos. It is not exactly what you need, but you should find something in there.

Regards.

troorl_ua
22nd April 2007, 11:37
The easiest way would be to use a linear gradients in combination with painter opacity for the shadow edges.

You could look at the Gradients example in the Qt Demos. It is not exactly what you need, but you should find something in there.

Regards.
I tried to work with gradients, but result is not accurate. Corners are not rounded and it look not beautifully
Maybe other way?

wysota
22nd April 2007, 13:11
Try the attached example (it works for backgroundless pixmaps as well and with little effort it should work for semi-transparent ones too). Use right and left mouse button to switch between different drawing modes.

If you want to change the way the shadow looks, adjust the filter.

wysota
22nd April 2007, 20:38
Here is an improved version. Optimised and working correctly for full alpha channeled images.

yogeshgokul
13th October 2008, 10:47
This is very very slow.

aamer4yu
13th October 2008, 11:07
There was some shadows example on Trolltech labs(Graphics/Dojo)
You can find it here (svn://labs.trolltech.com/svn/graphics/dojo/shadows)

yogeshgokul
13th October 2008, 11:57
Thank you for concern.

This example is rendering SVGs. But I want image files to be rendered with shadow. The old one, provided by Wysota, is doing same but that is too slow to be used.

spud
13th October 2008, 12:57
Well, you could optimize it. But firstly is it really too slow? Try drawing the shadow into a separate pixmap in the beginning and then just render it in the paintEvent(instead of generating it every time).
If that's still too slow for you, there are multiple ways of optimizing the function.

yogeshgokul
13th October 2008, 13:01
Thank you mate, this is very good example,
I gonna use it.;)