網(wǎng)上看了許多實現(xiàn)陰影效果的方法都不如這個簡單
效果圖
(一)基本思路
先將所有窗口控件拖到一個QFrame,然后用setWindowFlags()
設(shè)置窗口背景透明并使用QGraphicsDropShadowEffect
讓QFrame出現(xiàn)陰影鼎姐,于是冬骚,窗口像是本身被有了陰影效果劳闹。
(二)具體實現(xiàn)
-
void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on = true)
設(shè)置窗口背景透明
setAttribute(Qt::WA_TranslucentBackground);
-
QGraphicsDropShadowEffect
為子部件添加陰影
QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
shadow_effect->setOffset(-5, 5);
shadow_effect->setColor(Qt::gray);
shadow_effect->setBlurRadius(8);
ui->frame_main->setGraphicsEffect(shadow_effect);
注意要給QFrame上背景色
- 完事
(三)參考
http://blog.sina.com.cn/s/blog_a6fb6cc90101eoop.html
http://www.cppblog.com/biao/archive/2009/06/12/87508.html