问题描述
我想知道如何在 Qt 中的小部件(这不是主要小部件,例如标签)下绘制阴影.我需要使用样式表还是编写它(用 C++)?
假设您有一个表单和一个标签,要从中投射阴影.
您可以像这样使用 类,QGraphicsDropShadowEffect
也派生自该类.
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.
这篇关于如何在 Qt 的小部件下绘制阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!