RadialGradient QML Type
绘制径向渐变。更多...
| Import Statement: | import Qt5Compat.GraphicalEffects |
| Since: | QtGraphicalEffects 1.0 |
| Inherits: |
属性
- angle : real
- cached : bool
- gradient : Gradient
- horizontalOffset : real
- horizontalRadius : real
- source : variant
- verticalOffset : real
- verticalRadius : real
详细说明
渐变由两种或多种颜色构成,这些颜色之间无缝融合。颜色从元素中部开始,延伸至边缘。
| 已应用的效果 |
|---|
|
示例
以下示例演示了如何应用该效果。
import QtQuick
import Qt5Compat.GraphicalEffects
Item {
width: 300
height: 300
RadialGradient {
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: 0.5; color: "black" }
}
}
}属性文档
angle : real
此属性定义渐变围绕其中心点的旋转。只有当horizontalRadius 和verticalRadius 属性不相等时,该旋转才会显示出来。角度以度为单位,默认值为0 。
| 不同角度值的输出示例 | ||
|---|---|---|
|
|
|
| angle: 0 | angle: 45 | angle: 90 |
| horizontalOffset: 0 | horizontalOffset: 0 | horizontalOffset: 0 |
| verticalOffset: 0 | verticalOffset: 0 | verticalOffset: 0 |
| horizontalRadius: 100 | horizontalRadius: 100 | horizontalRadius: 100 |
| verticalRadius: 300 | verticalRadius: 300 | verticalRadius: 300 |
cached : bool
此属性允许将效果输出像素缓存起来,以提升渲染性能。
每次更改源或效果属性时,缓存中的像素都必须更新。由于需要额外的内存缓冲区来存储效果输出,因此内存消耗会增加。
当源或效果属性进行动画处理时,建议禁用缓存。
默认情况下,该属性设置为false 。
gradient : Gradient
渐变由两种或多种颜色定义,这些颜色会无缝融合。颜色通过一组GradientStop 子元素来指定,每个子元素都定义了渐变上从0.0到1.0之间的一个位置以及一种颜色。每个GradientStop 的位置通过设置position属性来定义,颜色则通过设置color属性来定义。
| 具有不同渐变值的输出示例 | ||
|---|---|---|
|
|
|
gradient: | gradient: | gradient: |
| horizontalOffset: 0 | horizontalOffset: 0 | horizontalOffset: 0 |
| verticalOffset: 0 | verticalOffset: 0 | verticalOffset: 0 |
| horizontalRadius: 300 | horizontalRadius: 300 | horizontalRadius: 300 |
| verticalRadius: 300 | verticalRadius: 300 | verticalRadius: 300 |
| angle: 0 | angle: 0 | angle: 0 |
horizontalOffset : real
horizontalOffset 和verticalOffset 属性定义了渐变中心点相对于项目中心的偏移量(以像素为单位)。
取值范围为 -inf 到 inf。默认情况下,这些属性设置为0 。
| 不同 horizontalOffset 值的输出示例 | ||
|---|---|---|
|
|
|
| horizontalOffset:-150 | horizontalOffset:0 | horizontalOffset:150 |
| verticalOffset: 0 | verticalOffset: 0 | verticalOffset: 0 |
| horizontalRadius: 300 | horizontalRadius: 300 | horizontalRadius: 300 |
| verticalRadius: 300 | verticalRadius: 300 | verticalRadius: 300 |
| angle: 0 | angle: 0 | angle: 0 |
horizontalRadius : real
horizontalRadius 和verticalRadius 属性用于定义径向渐变的形状和大小。如果两个半径相等,则渐变的形状为圆形;如果水平半径和垂直半径不同,则形状为椭圆形。半径以像素为单位。
取值范围为 -inf 到 inf。默认情况下,horizontalRadius 与宽度绑定,verticalRadius 与高度绑定。
| 不同 horizontalRadius 值下的输出示例 | ||
|---|---|---|
|
| |
| horizontalRadius: 300 | horizontalRadius: 100 | |
| horizontalOffset: 0 | horizontalOffset: 0 | |
| verticalOffset: 0 | verticalOffset: 0 | |
| verticalRadius: 300 | verticalRadius: 300 | |
| angle: 0 | angle: 0 | |
| gradient: QQuickGradient(0xa05fb10) | gradient: QQuickGradient(0xa05fb10) |
source : variant
此属性定义将填充渐变的元素。源元素会被渲染到一个中间像素缓冲区中,并根据结果中的透明度值来确定渐变在显示中的像素可见性。源的默认值为未定义,此时整个效果区域都会被渐变填充。
| 不同源值的输出示例 | ||
|---|---|---|
|
| |
| source: undefined | source: Image { source: images/butterfly.png } | |
| horizontalOffset: 0 | horizontalOffset: 0 | |
| verticalOffset: 0 | verticalOffset: 0 | |
| horizontalRadius: 300 | horizontalRadius: 300 | |
| verticalRadius: 300 | verticalRadius: 300 | |
| angle: 0 | angle: 0 |
注意: 不支持让效果包含自身,例如将源设置为该效果的父级。
verticalOffset : real
horizontalOffset 和 verticalOffset 属性定义了渐变中心点相对于项目中心的偏移量(以像素为单位)。
取值范围为 -inf 到 inf。默认情况下,这些属性设置为0 。
| 不同horizontalOffset 值下的输出示例 | ||
|---|---|---|
|
|
|
| horizontalOffset :-150 | horizontalOffset: 0 | horizontalOffset: 150 |
| verticalOffset:0 | verticalOffset:0 | 垂直偏移:0 |
| horizontalRadius: 300 | horizontalRadius: 300 | horizontalRadius: 300 |
| verticalRadius: 300 | verticalRadius: 300 | verticalRadius: 300 |
| angle: 0 | angle: 0 | angle: 0 |
verticalRadius : real
horizontalRadius 和 verticalRadius 属性用于定义径向渐变的形状和大小。如果两个半径相等,渐变的形状为圆形;如果水平半径和垂直半径不同,则形状为椭圆形。半径以像素为单位。
取值范围为 -inf 到 inf。默认情况下,horizontalRadius 与宽度绑定,verticalRadius 与高度绑定。
| 不同horizontalRadius 值下的输出示例 | ||
|---|---|---|
|
| |
| horizontalRadius :300 | horizontalRadius: 100 | |
| horizontalOffset: 0 | horizontalOffset: 0 | |
| verticalOffset: 0 | verticalOffset: 0 | |
| 垂直半径:300 | 垂直半径:300 | |
| angle: 0 | angle: 0 | |
| gradient: QQuickGradient(0xa05fb10) | gradient: QQuickGradient(0xa05fb10) |
© 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.













