其他分享
首页 > 其他分享> > Qt:绘制时,用线性渐变填充一个圆角矩形范围

Qt:绘制时,用线性渐变填充一个圆角矩形范围

作者:互联网

 1 void XXX::paintEvent(QPaintEvent *event)
 2 {
 3     QPainter painter(this);
 4     //圆角矩形范围
 5     QPainterPath path;
 6     path.addRoundedRect(this->rect(),10,10);
 7     //渐变颜色设置
 8     QLinearGradient linearGrad(0,0,0,this->height());
 9     linearGrad.setColorAt(0,Qt::blue);
10     linearGrad.setColorAt(1,Qt::red);
11     //绘制
12     painter.fillPath(path,linearGrad);
13 }

 

标签:10,圆角,Qt,渐变,setColorAt,linearGrad,path,painter
来源: https://www.cnblogs.com/Toya/p/16230312.html