当前位置: 代码迷 >> QT开发 >> 怎么在有背景色的控件下,显示子对象阴影
  详细解决方案

怎么在有背景色的控件下,显示子对象阴影

热度:93   发布时间:2016-04-25 04:04:14.0
如何在有背景色的控件上,显示子对象阴影
写了一个frame,上面有两个子对象,给frame加上阴影,如下
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    QGraphicsDropShadowEffect *e = new QGraphicsDropShadowEffect(this);
    e->setOffset(-5,5);
    e->setColor(QColor(19,29,31));
    e->setBlurRadius(8);
    ui->frame->setGraphicsEffect(e);

}

Dialog::~Dialog()
{
    delete ui;
}

代码如上。这个时候frame和他的子对象都有阴影显示
现在我让frame有背景色,比如设置ui->frame->setStyleSheet("background-color:rgb(123,31,22)");
或者ui->frame->setAutoFillBackground(true);
不能显示子对象阴影了就
谁知道怎么解决,或者有什么其它思路?

------解决方案--------------------
设置具体对象的stylesheet格式为
QFrame#frameName
{

}
这里setStyleSheet的参数最好这样写
QString::fromUtf8("")或者QString::fromUcs4()等,
------解决方案--------------------
不要用frame,对子控件单独设置effect
  相关解决方案