I am wondering how I would draw a shadow under a widget (which isn't the main widget, say, a label.) in Qt. Would I neeed use a stylesheet or would I code it (in C++)?
Say you have a form and a label you want to cast a shadow from.
You can use QGraphicsDropShadowEffect like so:
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
effect->setBlurRadius(5);
effect->setXOffset(5);
effect->setYOffset(5);
effect->setColor(Qt::black);
label->setGraphicsEffect(effect);
And the effect would be:
The downside of this effect is that if you apply it to a widget, all its children will inherit it. This could be problematic if you apply the effect on a widget with a lot of widgets because it could slow down the rendering time. But for your example this is perfectly fine and recommended.
For more information about effects in Qt
check the QGraphicsEffect class from which QGraphicsDropShadowEffect
is also derived.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With