PDA

View Full Version : Adding shadow effects to QPainter, QLabels and QPushButtons



anr78
3rd September 2010, 10:22
I've created my first GUI, mostly using QPainter, QLabels and QPushButtons. I've done a lot of white, but since the background sometimes will change to black, I need to add some sort of shadow / glow effect around my elements.

QPainter: The only clue I've found here is using a gradient brush as my pen. The problem is that the gradient is specified from an absolute coordinate, but I would like the centre of the gradient to always be at my pen-tip.

QPushButtons: Using stylesheets I've created colored buttons with white borders, but have no idea how to add shadows on the outside of the borders.

QLabels: Not a clue, but maybe I can use drawText instead, if I get my painter working?

wysota
3rd September 2010, 13:03
What is exactly that you want to do? I have trouble grasping your needs... Have you seen QGraphicsDropShadowEffect? It's suitable for widgets too.

anr78
3rd September 2010, 13:22
I have tested QGraphicsDropShadowEffect, but couldn't get it to do what I want.

Simply said (I hope), what I want to do is to add a soft black border around the white text in my qlabels, the white lines I paint with QPainter, and the white-bordered QPushButtons. This is because my gui is overlayed on video, and I want it to be clear both on black and white background. (And I need to use the white color).

Hope that explains it.

wysota
3rd September 2010, 13:23
Oh, ok... you want shadow around text, not around widgets. Probably the easiest way to do it globally is to supply your own QStyle implementation for text-related elements.

anr78
3rd September 2010, 13:44
I want it around both :)
Thanks for the answers.