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.