读书人

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

发布时间: 2013-03-10 09:38:39 作者: rapoo

如何在有背景色的控件上,显示子对象阴影
写了一个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

读书人网 >QT开发

热点推荐