RectangleShape QML Type

带边框的填充矩形。更多

Import Statement: import QtQuick.Shapes.DesignHelpers 6.10
Since: QtQuick 6.10

属性

详细说明

RectangleShape 用于用纯色或渐变填充区域,并提供一个矩形边框。

使用fillColor 属性指定的纯色填充或使用ShapeGradient 子类型定义并使用梯度属性设置的梯度来绘制每个矩形项。如果同时指定了颜色和渐变,则使用渐变。

通过设置strokeColorstrokeWidth 属性,可为矩形添加可选的边框,边框有自己的颜色和厚度。如果将颜色设置为transparent ,则会创建一个没有填充颜色的边框。

使用radius 属性可以绘制圆形矩形。也可以为每个角分别指定半径。此外,还可以在任何角上应用bevel ,将其截断。

RectangleShape 的 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
    }

属性文档

bottomLeftRadius : real

bottomRightRadius : real

topLeftRadius : real

topRightRadius : real

如果设置了这些属性,它们将定义各个角的半径。如果值为零,则该角为尖角;如果值为正,则该角为圆角。如果未设置,则使用radius 的值。

这些属性默认为未设置。将undefined 赋值给它们,可将它们返回到未设置状态。

在下面的示例中,radius 设置为10topLeftRadius 设置为0

    RectangleShape {
        id: rectangleShape
        anchors.centerIn: parent
        topLeftRadius: 0
        bottomRightBevel: true
        joinStyle: ShapePath.MiterJoin
    }

另请参阅 radius


bottomLeftBevel : bool

bottomRightBevel : bool

topLeftBevel : bool

topRightBevel : bool

如果设置了这些属性,它们将定义各个角的斜面。将它们设置为false 会产生尖角或圆角,具体取决于各个radius 属性的值。将它们设置为true 则会产生斜角。未设置时,将使用bevel 的值。

这些属性默认为未设置。将undefined 赋值给它们,可将它们返回到未设置状态。

在下面的示例中,bottomRightBevel 设置为 true:

    RectangleShape {
        id: rectangleShape
        anchors.centerIn: parent
        topLeftRadius: 0
        bottomRightBevel: true
        joinStyle: ShapePath.MiterJoin
    }

另请参阅 bevel


bevel : bool

该属性定义矩形的四角是否为斜角。

将其设置为false 会导致尖角或圆角,具体取决于各个radius 属性的值。

该属性可被各个斜角属性覆盖。

    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


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().


fillColor : color

该属性用于保存填充颜色。

当设置为transparent 时,不会发生填充。

默认值为"white"

注意: 如果将fillGradient 设置为null 以外的值,则将使用该值代替fillColor


fillGradient : ShapeGradient

矩形填充颜色的 fillGradient。

默认情况下,不启用 fillGradient,且值为空。在这种情况下,填充将使用基于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

该属性定义了用于定义圆角矩形的角半径。

如果半径为正值,矩形路径将被定义为圆角矩形,否则将被定义为普通矩形。

该属性可被各个边角半径属性覆盖。

默认值为10

另请参阅 topLeftRadius,topRightRadius,bottomLeftRadius, 和bottomRightRadius


strokeColor : color

该属性包含描边颜色。

当设置为transparent 时,不会出现描边。

默认值为"black"


strokeStyle : enumeration

该属性定义了描边的样式。默认值为ShapePath.SolidLine。

常数说明
ShapePath.SolidLine普通线条。
ShapePath.DashLine由几个像素分隔的虚线。

strokeWidth : real

该属性用于保存描边宽度。

当设置为负值时,不会出现描边。

默认值为1


© 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.