首页 > 其他 > 详细

Qt窗口的阴影边框

时间:2017-04-15 12:22:53      阅读:620      评论:0      收藏:0      [点我收藏+]

将窗口设置为透明(setAttribute(Qt::WA_TranslucentBackground);)

然后重载paintEvent:

void MyWidget::paintEvent(QPaintEvent *event)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10, 10, this->width() - 20, this->height() - 20);

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillPath(path, QBrush(Qt::white));

QColor color(0, 0, 0, 50);
for (int i = 0; i < 10; i++)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10 - i, 10 - i, this->width() - (10 - i) * 2, this->height() - (10 - i) * 2);
color.setAlpha(150 - qSqrt(i) * 50);
painter.setPen(color);
painter.drawPath(path);
}
}

Qt窗口的阴影边框

原文:http://www.cnblogs.com/linning-blog/p/6713251.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!