QLinearGradient Class

QLinearGradient 类与QBrush 结合使用,用于指定线性渐变笔刷。更多

Header: #include <QLinearGradient>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QGradient

公共函数

QLinearGradient()
QLinearGradient(const QPointF &start, const QPointF &finalStop)
QLinearGradient(qreal x1, qreal y1, qreal x2, qreal y2)
QPointF finalStop() const
void setFinalStop(const QPointF &stop)
void setFinalStop(qreal x, qreal y)
void setStart(const QPointF &start)
void setStart(qreal x, qreal y)
QPointF start() const

详细说明

线性渐变在起点和终点之间插入颜色。在这些点之外,根据当前设置的spread 方法,渐变会被填充、反射或重复:

使用QGradientStop 类型的停止点(即一个位置和一种颜色)定义渐变中的颜色。使用QGradient::setColorAt() 或QGradient::setStops() 函数定义停止点。梯度的整套停止点描述了梯度区域的填充方式。如果没有指定停止点,则会使用从 0 到 1 的黑白渐变。

除了从QGradient 继承的函数外,QLinearGradient 类还提供了finalStop() 函数(返回梯度的最终停止点)和start() 函数(返回梯度的起始点)。

另请参阅 QRadialGradient,QConicalGradient梯度示例

成员函数文档

QLinearGradient::QLinearGradient()

构建一个默认的线性梯度,插值区域在(0,0)和(1,1)之间。

另请参见 QGradient::setColorAt()、setStart() 和setFinalStop()。

QLinearGradient::QLinearGradient(const QPointF &start, const QPointF &finalStop)

在给定的start 点和finalStop 之间构建一个具有插值区域的线性梯度。

注: 预期参数值以像素为单位。

另请参阅 QGradient::setColorAt() 和QGradient::setStops() 。

QLinearGradient::QLinearGradient(qreal x1, qreal y1, qreal x2, qreal y2)

在 (x1,y1) 和 (x2,y2) 之间构建一个具有插值区域的线性梯度。

注: 预期参数值以像素为单位。

另请参见 QGradient::setColorAt() 和QGradient::setStops()。

QPointF QLinearGradient::finalStop() const

以逻辑坐标形式返回该线性梯度的最终停止点。

另请参阅 setFinalStop() 和QGradient::stops()。

void QLinearGradient::setFinalStop(const QPointF &stop)

用逻辑坐标将此线性梯度的最终停止点设置为stop

另请参见 finalStop() 。

void QLinearGradient::setFinalStop(qreal x, qreal y)

这是一个重载函数。

在逻辑坐标中将此线性梯度的最终停止点设置为x,y

另请参见 start().

void QLinearGradient::setStart(const QPointF &start)

将逻辑坐标中的线性梯度起点设置为start

另请参见 start().

void QLinearGradient::setStart(qreal x, qreal y)

这是一个重载函数。

在逻辑坐标中将此线性梯度的起点设置为x,y

另请参见 start().

QPointF QLinearGradient::start() const

以逻辑坐标形式返回该线性梯度的起点。

另请参阅 setStart() 和QGradient::stops()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.