DelegateStyle QML Type
定义控件中元素的视觉外观。更多
| Import Statement: | import Qt.labs.StyleKit |
| Inherited By: |
属性
- alignment : Qt::Alignment
- border : BorderStyle
- bottomLeftRadius : real
- bottomMargin : real
- bottomRightRadius : real
- clip : bool
- color : color
- data : QObject
- delegate : Component
- gradient : Gradient
- image : ImageStyle
- implicitHeight : real
- implicitWidth : real
- leftMargin : real
- margins : real
- minimumWidth : real
- opacity : real
- radius : real
- rightMargin : real
- rotation : real
- scale : real
- shadow : ShadowStyle
- topLeftRadius : real
- topMargin : real
- topRightRadius : real
- visible : bool
详细说明
DelegateStyle 描述ControlStyle 中可视元素的视觉外观,如background,indicator, 或子元素(如indicator.foreground )。它提供了用于控制size,color,border,radius,shadow,image,opacity 等的属性。
注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。
另请参阅 ControlStyle,ControlStateStyle, 和FallbackStyle 参考。
属性文档
alignment : Qt::Alignment
代表在父代中的对齐方式。默认值为Qt.AlignLeft | Qt.AlignVCenter 。
border : BorderStyle
分组属性,用于设计此委托的边框样式。
bottomLeftRadius : real
左下角半径。如果未设置,则返回radius 。
另请参阅 radius,topLeftRadius,topRightRadius, 和bottomRightRadius 。
bottomMargin : real
该代表的底边距。如果未设置,则返回margins 。
另请参阅 margins,topMargin,leftMargin, 和rightMargin 。
bottomRightRadius : real
右下角半径。如果未设置,则返回radius 。
另请参阅 radius,topLeftRadius,topRightRadius, 和bottomLeftRadius 。
clip : bool
委托是否剪辑其内容。默认值是false 。
color : color
该代表的填充颜色。默认值为transparent 。
与快速Rectangle 不同的是,StyleKit 是在颜色之上绘制gradient 。这意味着您可以使用半透明的渐变作为叠加(例如,微妙的阴影效果),而颜色则在下面显示出来。
button { background.gradient: Gradient { GradientStop { position: 0.0; color: Qt.alpha("black", 0.0)} GradientStop { position: 1.0; color: Qt.alpha("black", 0.2)} } background.color: "lightsteelblue" hovered.background.color: Qt.darker("lightsteelblue", 1.1) pressed.background.color: Qt.darker("lightsteelblue", 1.2) }
data : QObject
可用于将自定义数据从样式传递到自定义delegate 组件的任意对象。
这样,您就可以定义超出StyleKit API 所提供的自定义样式属性。数据对象可以在不同的状态和主题下变化,从而可以在自定义delegate 中为内置属性未涵盖的元素设计样式。
下面的代码段使用了一个自定义委托,该委托绘制了一个叠加Text ,其颜色根据控件的状态而变化。该委托继承了StyledItem ,它是可选的,但可确保按钮背景的其余部分正常呈现。
component OverlayData : QtObject { property color overlayColor } toolButton { background.delegate: StyledItem { id: custom Text { color: custom.delegateStyle.data.overlayColor font.pixelSize: 30 text: "シ" } } background.data: OverlayData { overlayColor: "sandybrown" } hovered.background.data: OverlayData { overlayColor: "magenta" } }
注意: data 对象是作为一个整体传播的。与常规样式属性不同,数据对象内的单个属性不会单独传播。
另请参阅 delegate 。
delegate : Component
用于在Qt Quick 控件中渲染DelegateStyle 的委托。
默认值为null ,在这种情况下,将使用StyledItem 代替呈现。
委托需要定义以下必要属性:
required property DelegateStyle delegateStyle required property QtObject control
delegateStyle DelegateStyle control 指向拥有该委托的Qt Quick 控件。后者可用于解析样式中无法提供的有关控件的其他信息。
如果知道拥有该委托的控件的具体类型,就可以用它来代替QtObject 作为control 属性。例如,由于下面代码段中的句柄委托总是在滑块内部使用,因此可以将类型设为T.Slider :
// import QtQuick.Templates as T slider { handle.delegate: Rectangle { id: handle required property DelegateStyle delegateStyle required property T.Slider control implicitWidth: delegateStyle.implicitWidth implicitHeight: delegateStyle.implicitHeight radius: delegateStyle.radius color: delegateStyle.color Text { anchors.centerIn: parent text: handle.control.value.toFixed(0) } } }
注意: 如果DelegateStyle 已定义了drop shadow ,则将通过一个"...... "属性单独绘制。shadow delegate.
另请参阅 data 和StyledItem 。
gradient : Gradient
该代表的渐变效果。默认值为null (无渐变)。
在快速Rectangle 中,渐变会取代颜色,而StyleKit 则不同,它会在颜色之上绘制渐变。这意味着您可以使用半透明的渐变作为叠加(例如,微妙的阴影效果),而颜色则在下面显示出来。
button { background.gradient: Gradient { GradientStop { position: 0.0; color: Qt.alpha("black", 0.0)} GradientStop { position: 1.0; color: Qt.alpha("black", 0.2)} } background.color: "lightsteelblue" hovered.background.color: Qt.darker("lightsteelblue", 1.1) pressed.background.color: Qt.darker("lightsteelblue", 1.2) }
另请参见 color 。
image : ImageStyle
分组属性,用于在此委托内放置图片。
另请参阅 ImageStyle 。
implicitHeight : real
该委托的隐式高度。
implicitWidth : real
此委托的隐式宽度。将其设置为Style.Stretch ,可使委托填满控件的可用宽度。
leftMargin : real
该代表的左边距。如果未设置,则返回margins 。
另请参阅 margins,rightMargin,topMargin, 和bottomMargin 。
margins : real
该代表周围的统一边距。设置此项可为leftMargin,rightMargin,topMargin, 和bottomMargin 提供默认值。每一边都可以单独重写。
另请参阅 leftMargin,rightMargin,topMargin 和bottomMargin 。
minimumWidth : real
此委托的最小宽度。代表的大小不会小于此值。
opacity : real
此委托的不透明度,从0.0 (完全透明)到1.0 (完全不透明)。默认值为1.0 。
radius : real
应用于该委托所有四个角的角半径。可以通过topLeftRadius,topRightRadius,bottomLeftRadius 和bottomRightRadius 来覆盖单个角。
另请参阅 topLeftRadius,topRightRadius,bottomLeftRadius 和bottomRightRadius 。
rightMargin : real
该代表的右边距。如果未设置,则返回margins 。
另请参见 margins,leftMargin,topMargin, 和bottomMargin 。
rotation : real
该代表的旋转角度。
scale : real
该代表的比例因子。默认值为1.0 。
shadow : ShadowStyle
分组属性,用于为此代表后面的阴影设计样式。
另请参见 ShadowStyle 。
topLeftRadius : real
左上角半径。如果未设置,则返回radius 。
另请参阅 radius,topRightRadius,bottomLeftRadius, 和bottomRightRadius 。
topMargin : real
该代表的顶边距。如果未设置,则返回margins 。
另请参见 margins,bottomMargin,leftMargin, 和rightMargin 。
topRightRadius : real
右上角半径。如果未设置,则返回radius 。
另请参见 radius,topLeftRadius,bottomLeftRadius, 和bottomRightRadius 。
visible : bool
此委托是否可见。默认值为true 。
注: 虽然默认值为true ,但对于通常不应绘制背景的控件,如CheckBox 、RadioButton 和Slider ,fallback style (可覆盖许多默认值)将background.visible 设置为false 。
另请参阅 opacity 。
© 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.