QLinearGradient Class
QLinearGradient 类与QBrush 结合使用,用于指定线性渐变画笔。更多内容...
| 头文件: | #include <QLinearGradient> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 继承自: | QGradient |
- 所有成员列表(包括继承的成员)
- QLinearGradient 属于绘图类。
公共函数
| 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()。
© 2026 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.


