QT | 探究background-color: qlineargradient

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39419087/article/details/81304294

恩,

QPushButton:pressed{
	background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #dadbde, stop:1 #f6f7f);
}

这个background-color: qlineargradient这句代码是啥子意思,怎么用的。

网上找,不知道答案。查阅help文档:

The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush.

这个QLinearGradient类用于与QBrush一起,指定一个线性渐变画笔。

Linear gradients interpolate colors between start and end points. Outside these points the gradient is either padded, reflected or repeated depending on the currently set spread method:

在起点和终点之间线性梯度地插入颜色。在这些点之外,梯度也是根据当前设置spread方法来填充、反射或重复。

The colors in a gradient is defined using stop points of the QGradientStop type, i.e. a position and a color. Use the QGradient::setColorAt() or the QGradient::setStops() function to define the stop points. It is the gradient's complete set of stop points that describes how the gradient area should be filled. If no stop points have been specified, a gradient of black at 0 to white at 1 is used.

使用QGradientStop类型的stop points来定义梯度的颜色,比如,一个位置和颜色,使用QGradient::setColorAt()或者QGradient::setStops()方法来定义stop points。这是一个完整的stop points的梯度设置,描述梯度区域被如何进行填充。如果没有指定stop points,则默认使用0为黑,1为白的梯度。

In addition to the functions inherited from QGradient, the QLinearGradient class provides the finalStop() function which returns the final stop point of the gradient, and the start() function returning the start point of the gradient.

除了继承自 QGradient的方法, QLinearGradient类也提供了 finalStop()方法,用来返回梯度的最终stop point; start()方法用来返回梯度的start point。

现在只能猜想,这是一个设置背景颜色渐变的。

(1)如果改成:

(2)如果改成

(3)如果改成

(4)如果改成

从上面的四个结果,猜想:

假想背景为1X1的一个区域,x1,y1表示起点,x2,y2表示终点。渐变方向为起点指向终点,stop后面的数值为……不会总结了,对(2)分析见图:

猜你喜欢

转载自blog.csdn.net/qq_39419087/article/details/81304294