RectangleShape QML Type
一个带填充色的矩形,可选边框。更多...
| Import Statement: | import QtQuick.Shapes.DesignHelpers 6.12 |
| Since: | QtQuick 6.10 |
属性
- bevel : bool
- borderMode : enumeration
- bottomLeftBevel : bool
- bottomLeftRadius : real
- bottomRightBevel : bool
- bottomRightRadius : real
- capStyle : enumeration
- dashOffset : real
- dashPattern : list<real>
- drawBottom : bool
(since 6.11) - drawLeft : bool
(since 6.11) - drawRight : bool
(since 6.11) - drawTop : bool
(since 6.11) - fillColor : color
- fillGradient : ShapeGradient
- fillRule : enumeration
- joinStyle : enumeration
- radius : real
- strokeColor : color
- strokeStyle : enumeration
- strokeWidth : real
- topLeftBevel : bool
- topLeftRadius : real
- topRightBevel : bool
- topRightRadius : real
详细说明
RectangleShape 用于将区域填充为纯色或渐变色,并添加矩形边框。
每个 Rectangle 项的绘制可采用纯色填充(通过fillColor 属性指定)或渐变填充(通过ShapeGradient 子类型之一定义,并使用gradient属性设置)。如果同时指定了纯色和渐变,则使用渐变。
可以通过设置strokeColor 和strokeWidth 属性,为矩形添加具有自定义颜色和粗细的可选边框。将颜色设置为transparent 可创建无填充色的边框。
可通过radius 属性绘制圆角矩形。每个角的半径也可单独指定。此外,可在任意角应用bevel 属性以将其锐角切除。
RectangleShape 对象中QtQuick.Shapes::Shape::preferredRendererType 的默认值为Shape.CurveRenderer 。
用法示例
RectangleShape {
id: rectangleShape
anchors.centerIn: parent
radius: 0
topLeftRadius: 30
bottomRightRadius: 30
bevel: true
joinStyle: ShapePath.MiterJoin
fillColor: "#3ad23c"
strokeColor: "transparent"
visible: false
}
属性文档
bevel : bool
此属性用于定义矩形的角是否为斜角。
将其设置为false 将导致尖角或圆角,具体取决于各个radius 属性的值。
该属性可能会被各个 bevel 属性覆盖。
RectangleShape {
id: rectangleShape
anchors.centerIn: parent
radius: 0
topLeftRadius: 30
bottomRightRadius: 30
bevel: true
joinStyle: ShapePath.MiterJoin
fillColor: "#3ad23c"
strokeColor: "transparent"
visible: false
}
另请参阅 topLeftBevel 、topRightBevel 、bottomLeftBevel 和bottomRightBevel 。
borderMode : enumeration
borderMode 属性决定了边框在矩形边缘的何处绘制。
| 常量 | 描述 |
|---|---|
RectangleShape.Inside | 边框沿项目的内边缘绘制,且不影响项目宽度。 |
这是默认值。
| 常量 | 描述 |
|---|---|
RectangleShape.Middle | 边框沿项目的边缘绘制,不会影响项目的宽度。 |
RectangleShape.Outside | 边框沿项目的外部边缘绘制,并使项目宽度增加strokeWidth 的值。 |
另请参阅 strokeWidth 。
如果设置了这些属性,它们将定义各个角的倒角效果。将其设置为false 将产生锐角或圆角,具体取决于各个radius 属性的值。将其设置为true 将产生斜面角。如果未设置这些属性,则改用bevel 的值。
这些属性默认处于未设置状态。若要将其恢复为未设置状态,请将undefined 赋值给这些属性。
在下面的示例中,bottomRightBevel 被设置为 true:
RectangleShape {
id: rectangleShape
anchors.centerIn: parent
topLeftRadius: 0
bottomRightBevel: true
joinStyle: ShapePath.MiterJoin
}
另请参阅 bevel 。
如果设置了这些属性,它们将定义各个角的圆角半径。值为零表示该角为锐角,而正值则表示该角为圆角。如果未设置,则改用radius 的值。
这些属性默认处于未设置状态。将 `undefined ` 赋值给它们,即可将其恢复为未设置状态。
在下面的示例中,radius 被设置为10 ,topLeftRadius 被设置为0 :
RectangleShape {
id: rectangleShape
anchors.centerIn: parent
topLeftRadius: 0
bottomRightBevel: true
joinStyle: ShapePath.MiterJoin
}
另请参阅 radius 。
capStyle : enumeration
此属性定义了线条端点的绘制方式。默认值为ShapePath.SquareCap 。
| 常量 | 描述 |
|---|---|
ShapePath.FlatCap | 方形线端,不覆盖线的端点。 |
ShapePath.SquareCap | 方形线端,不覆盖线的端点,且向外延伸的距离为线宽的一半。 |
ShapePath.RoundCap | 圆角线端。 |
dashOffset : real
此属性定义了虚线图案的起始点,其测量单位与指定虚线图案时所用的单位相同。
默认值为0 。
另请参阅 QPen::setDashOffset()。
dashPattern : list<real>
当strokeStyle 设置为ShapePath.DashLine时,此属性定义了连线图案。该图案必须由偶数个正值条目指定,其中第1、3、5…个条目为连线,第2、4、6…个条目为空格。图案以笔宽为单位进行指定。
默认值为 (4, 2),表示一个长度为 4 *strokeWidth 像素的短划线,后跟一个宽度为 2 *strokeWidth 像素的空格。
另请参阅 QPen::setDashPattern()。
drawBottom : bool [since 6.11]
该属性控制是否绘制底部边框。
默认值为true 。
该属性自 Qt 6.11 起引入。
drawLeft : bool [since 6.11]
该属性控制是否绘制左边框。
默认值为true 。
该属性自 Qt 6.11 起引入。
drawRight : bool [since 6.11]
该属性控制是否绘制右边框。
默认值为true 。
该属性在 Qt 6.11 中引入。
drawTop : bool [since 6.11]
该属性控制是否绘制顶部边框。
默认值为true 。
该属性在 Qt 6.11 中引入。
fillColor : color
该属性用于指定填充颜色。
当设置为transparent 时,不会进行填充。
默认值为"white" 。
注意:如果 将fillGradient 设置为null 以外的值,则将使用该值代替fillColor 。
fillGradient : ShapeGradient
矩形填充颜色的填充渐变(fillGradient)。
默认情况下,fillGradient 未启用,其值为 null。在此情况下,填充将根据fillColor 的值使用纯色。
当设置此属性时,fillColor 将被忽略,填充将使用ShapeGradient 子类型之一进行。
注意: 此处不能使用Gradient 类型 。建议优先使用LinearGradient 等高级子类型。
fillRule : enumeration
此属性用于指定填充规则。默认值为ShapePath.OddEvenFill 。有关填充规则的说明,请参阅QPainterPath::setFillRule()。
| 常量 | 描述 |
|---|---|
ShapePath.OddEvenFill | 奇偶填充规则。 |
ShapePath.WindingFill | 非零绕行填充规则。 |
joinStyle : enumeration
此属性定义了两条相连线段之间的连接线如何绘制。默认值为ShapePath.BevelJoin 。
| 常量 | 描述 |
|---|---|
ShapePath.MiterJoin | 两条线的外部边缘会延伸并以一定角度相交,该区域会被填充。 |
ShapePath.BevelJoin | 两条线之间的三角形缺口被填充。 |
ShapePath.RoundJoin | 两条线之间的圆弧区域被填充。 |
radius : real
此属性定义了用于绘制圆角矩形的圆角半径。
如果 radius 为正值,则矩形路径将被定义为圆角矩形;否则,将被定义为普通矩形。
该属性可被各个角半径属性覆盖。
默认值为10 。
另请参阅 topLeftRadius 、topRightRadius 、bottomLeftRadius 和bottomRightRadius 。
strokeColor : color
此属性用于指定描边颜色。
当设置为transparent 时,不会出现描边效果。
默认值为"black" 。
strokeStyle : enumeration
此属性定义了线条的样式。默认值为ShapePath.SolidLine。
| 常量 | 描述 |
|---|---|
ShapePath.SolidLine | 一条实线。 |
ShapePath.DashLine | 间隔几个像素的虚线。 |
strokeWidth : real
该属性用于设置笔画宽度。
当设置为负值时,不会进行描边。
默认值为1 。
© 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.