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 }

 

posted @ 2022-05-06 20:25  _KikyoBK  Views(368)  Comments(0Edit  收藏  举报