本页内容

PathRectangle QML Type

定义一个矩形,可选地将角落圆角化。更多...

Import Statement: import QtQuick
Since: QtQuick 6.8

属性

详细说明

PathRectangle 提供了一种简便的方法来指定矩形,可选地设置圆角或斜角。该 API 与Rectangle 项的 API 相对应。

带倒角的矩形

    Shape {
        id: rectangleShape
        width: 200
        height: 150
        anchors.centerIn: parent
        preferredRendererType: Shape.CurveRenderer

        ShapePath {
            fillColor: "#3ad23c"

            PathRectangle {
                width: rectangleShape.width
                height: rectangleShape.height
                topLeftRadius: 30
                bottomRightRadius: 30
                bevel: true
            }
        }
    }

另请参阅 Path 、PathLine 、PathQuad 、PathCubic 、PathArc 、PathAngleArc 、PathCurve 以及PathSvg 。

属性文档

bevel : bool [since 6.10]

此属性用于定义矩形的角是否为斜角。

将其设置为false 将产生锐角或圆角,具体取决于各个radius 属性的值。

该属性可能会被各个 bevel 属性覆盖。

    Shape {
        id: rectangleShape
        width: 200
        height: 150
        anchors.centerIn: parent
        preferredRendererType: Shape.CurveRenderer

        ShapePath {
            fillColor: "#3ad23c"

            PathRectangle {
                width: rectangleShape.width
                height: rectangleShape.height
                topLeftRadius: 30
                bottomRightRadius: 30
                bevel: true
            }
        }
    }

左上角和右下角呈斜切状的矩形

该属性在 Qt 6.10 中引入。

另请参阅 topLeftBevel 、topRightBevel 、bottomLeftBevel 和bottomRightBevel 。

bottomLeftBevel : bool

bottomRightBevel : bool

topLeftBevel : bool

topRightBevel : bool

如果设置了这些属性,它们将定义各个角的倒角。将其设置为false 将生成锐角或圆角,具体取决于各个radius 属性的值。将其设置为true 将生成斜面角。如果未设置,则改用bevel 的值。

这些属性默认处于未设置状态。若要将其恢复为未设置状态,请将其值设为undefined 。

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

    Shape {
        id: rectangleShape
        width: 200
        height: 150
        anchors.centerIn: parent
        preferredRendererType: Shape.CurveRenderer

        ShapePath {
            strokeColor: "black"
            strokeWidth: 4
            joinStyle: ShapePath.MiterJoin

            PathRectangle {
                width: rectangleShape.width
                height: rectangleShape.height
                radius: 10
                topLeftRadius: 0
                bottomRightBevel: true
            }
        }
    }

一个矩形轮廓,其中三个角为圆角,一个角为斜角

另请参阅 bevel 。

bottomLeftRadius : real

bottomRightRadius : real

topLeftRadius : real

topRightRadius : real

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

这些属性默认处于未设置状态。将undefined 赋值给它们,即可将其恢复为未设置状态。

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

    Shape {
        id: rectangleShape
        width: 200
        height: 150
        anchors.centerIn: parent
        preferredRendererType: Shape.CurveRenderer

        ShapePath {
            strokeColor: "black"
            strokeWidth: 4
            joinStyle: ShapePath.MiterJoin

            PathRectangle {
                width: rectangleShape.width
                height: rectangleShape.height
                radius: 10
                topLeftRadius: 0
                bottomRightBevel: true
            }
        }
    }

一个矩形轮廓,其中三个角为圆角,一个角为斜角

另请参阅 radius 。

height : real

width : real

定义矩形的宽度和高度。

另请参阅 x 和y 。

radius : real

此属性用于定义用于绘制圆角矩形的圆角半径。

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

该属性可被各个单独的圆角半径属性覆盖。

默认值为0 。

另请参阅 topLeftRadius 、topRightRadius 、bottomLeftRadius 和bottomRightRadius 。

relativeX : real

relativeY : real

定义矩形相对于路径起点的左上角。

如果针对同一坐标轴同时指定了相对和绝对的结束位置,则将使用相对位置。

相对位置和绝对位置可以混合使用,例如,设置相对的 x 坐标和绝对的 y 坐标是有效的。

另请参阅 x 和y 。

strokeAdjustment : real

此属性定义了矩形坐标对应的描边宽度调整。

当在启用了描边功能的ShapePath 中使用时,实际描边的矩形默认会在所有边上超出定义矩形半个描边宽度。这是预期的行为,因为路径定义了描边的中点线,并且符合QPainter 和SVG的渲染规范。

如果希望定义的矩形成为描边矩形的外部边缘(例如带有边框的Rectangle 项),则可将strokeAdjustment设置为描边宽度。这将有效地将所有边缘向内偏移半个描边宽度。如下例所示:

ShapePath {
    id: myRec
    fillColor: "white"
    strokeColor: "black"
    strokeWidth: 16
    joinStyle: ShapePath.MiterJoin

    PathRectangle { x: 10; y: 10; width: 200; height: 100; strokeAdjustment: myRec.strokeWidth }
}

x : real

y : real

定义矩形的左上角。

除非该角为圆角,否则这里也将是路径的起点和终点。

另请参阅 relativeX 和relativeY 。

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