How would I draw a shadow under widgets in Qt?

I am wondering how I would draw a shadow under the widgets (which is not the main widgets, say shortcut.) In Qt. Can I use a stylesheet or would I code it (in C ++)?

+4
source share
2 answers

Say that you have a shape and a label from which you want to cast a shadow.

You can use QGraphicsDropShadowEffect like this:

QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; effect->setBlurRadius(5); effect->setXOffset(5); effect->setYOffset(5); effect->setColor(Qt::black); label->setGraphicsEffect(effect); 

And the effect will be:

enter image description here

The disadvantage of this effect is that if you apply it to a widget, all its children inherit it. This can be problematic if you apply the effect to a widget with a large number of widgets, because it can slow down the rendering time. But for your example, this is fine and recommended.

For more information about the effects in Qt check out the QGraphicsEffect class, from which QGraphicsDropShadowEffect is also derived.

+3
source

QLabel inherits from QFrame . You can use this to create shadows.

0
source

Source: https://habr.com/ru/post/1433100/


All Articles