PathRectangle QML Type
定义带圆角的矩形。更多
Import Statement: | import QtQuick |
Since: | QtQuick 6.8 |
属性
- bevel : bool
(since 6.10)
- bottomLeftBevel : bool
- bottomLeftRadius : real
- bottomRightBevel : bool
- bottomRightRadius : real
- height : real
- radius : real
- relativeX : real
- relativeY : real
- strokeAdjustment : real
- topLeftBevel : bool
- topLeftRadius : real
- topRightBevel : bool
- topRightRadius : real
- width : real
- x : real
- y : real
详细说明
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 。
属性文档
如果设置了这些属性,它们将定义各个角的半径。如果值为零,则该角为尖角;如果值为正,则该角为圆角。如果未设置,则使用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 。
如果设置了这些属性,它们将定义各个角的斜面。将它们设置为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 。
bevel : bool |
该属性定义矩形的四角是否为斜角。
将其设置为false
会导致尖角或圆角,具体取决于各个radius 属性的值。
该属性可被各个斜角属性覆盖。
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 。
radius : real |
该属性定义用于定义圆角矩形的角半径。
如果半径为正值,矩形路径将被定义为圆角矩形,否则将被定义为普通矩形。
该属性可被各个边角半径属性覆盖。
默认值为0
。
另请参阅 topLeftRadius,topRightRadius,bottomLeftRadius, 和bottomRightRadius 。
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 } }
© 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.