前言:
现时小伙伴们对“an怎么改渐变方向”大约比较关注,小伙伴们都需要学习一些“an怎么改渐变方向”的相关知识。那么小编在网摘上收集了一些有关“an怎么改渐变方向””的相关知识,希望姐妹们能喜欢,你们快快来了解一下吧!扩展的辐射渐变构造函数:
QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius)
---Constructs an extended radial gradient with the given center, centerRadius, focalPoint, and focalRadius.
【译文:构造一个扩展的辐射渐变,中心圆的圆点是center,半径是centerRadius;焦点圆的圆心focalPoint,半径focalRadius。】
--- Extended radial gradients interpolate colors between a focal circle and a center circle. Points outside the cone defined by the two circles will be transparent.
【译文:扩展的辐射渐变,在焦点圆和中心圆之间插入颜色。由两个圆定义的锥形之外的点变成透明的,即不会被填充。】
在“扩展的辐射渐变”这种模式中,有“中心圆”、“焦点圆”、“锥形区域”,文档中的这些名词,到底如何理解?为了搞清楚这些细节,笔者经过研究,构造了一个辐射渐变对象,根据要求提供了中心圆(图中左侧的大圆)、焦点圆(图中右侧的小圆),设置了四种插值的颜色,在此基础上,绘制了窗体的边框,这样,就可以直观见到文档中所说的锥形区域了。程序运行的效果见下图所示,笔者的测试代码附在其后:
void Widget::paintEvent(QPaintEvent *event)
{
const int r = 400;
QPainter painter(this);
//move origin to the center
painter.translate(width()/2.0,height()/2.0);
painter.setPen(QPen(Qt::black));
/*creat a radial grdient object by given center circle and focal circle.
center circle: its center is QPointF(0,0), radius is r/2.0
focal circle: its center is QPointF(r,0), radius is r/4.0. */
QRadialGradient radialGradient(QPointF(0,0),r/2.0,QPointF(r,0),r/4.0);
//interpolate colors from focal circle to center circle
radialGradient.setColorAt(0.0, Qt::red);
radialGradient.setColorAt(0.3, Qt::yellow);
radialGradient.setColorAt(0.6, Qt::blue);
radialGradient.setColorAt(1.0, Qt::magenta);
//set radial gradient to brush's style
QBrush brush(radialGradient);
painter.setBrush(brush);
/*draw a border of the widget with the brush of specified style
and you will see the entire cone defined by center circle and focal circle*/
painter.drawRect(-width()/2,-height()/2,width(),height());
/*redefine the brush to Qt::Nobrsh,
so as to draw center circle and focal circle. */
painter.setBrush(QBrush(Qt::NoBrush));
painter.drawEllipse(QPoint(0, 0), r/2.0, r/2.0);
painter.drawEllipse(QPoint(r, 0), r/4.0, r/4.0);
//Set font's family and pointSize to painter
painter.setFont(QFont("Times New Roman",20));
//draw the tabs of center circle and focal circle
painter.drawText(-60,0,"Center circle");
painter.drawText(0.77*r,0,"Focal circle");
}
小结:通过本文的测试,搞清楚了辐射渐变中的"扩展的辐射渐变“的用法细节。
标签: #an怎么改渐变方向 #an怎么调整渐变方向