ControlStyleProperties QML Type
定义控件的可风格化属性。更多
| Import Statement: | import Qt.labs.StyleKit |
| Inherited By: | ControlStateStyle, ControlStyle, CustomControl, and StyleReader |
属性
- background : DelegateStyle
- bottomPadding : real
- handle : HandleStyle
- indicator : IndicatorStyle
- leftPadding : real
- padding : real
- rightPadding : real
- spacing : real
- text : TextStyle
- topPadding : real
- transition : Transition
详细说明
ControlStyleProperties 定义了控件的样式属性:可视化构件background,indicator,handle, 和text, 以及布局属性padding,spacing, 和transition 。
样式属性可通过继承类型(如ControlStyle 和StyleReader )访问。
注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。
另请参阅 ControlStyle,StyleReader,ControlStateStyle, 和DelegateStyle 。
属性文档
background : DelegateStyle
用于设置控件背景样式的分组属性。
背景委托通常是控件后面的主视觉矩形。使用它可设置colors,borders,radii,shadows,gradients 和images 。
注: 对于通常不应绘制背景的控件,如CheckBox,RadioButton 和Slider ,默认设置fallback style 将background.visible 设置为false 。要显示它们的背景,请明确将background.visible 设置为true 。
bottomPadding : real
控件的bottom padding 。如果未设置,则返回padding 。
另请参阅 padding,topPadding,leftPadding 和rightPadding 。
handle : HandleStyle
分组属性,用于设置控件句柄的样式。
Switch,Slider, 和RangeSlider 等控件都使用了句柄。对于RangeSlider ,可通过handle.first 和handle.second 对两个句柄分别进行样式设置。
另请参阅 HandleStyle 和DelegateStyle 。
indicator : IndicatorStyle
用于设计控件指示符样式的分组属性。对于checkBox ,指示符是框架,其foreground 是复选标记。对于slider ,指示符是凹槽,前景是填充。
另请参阅 DelegateStyle 。
leftPadding : real
控件的left padding 。如果未设置,则返回padding 。
另请参阅 padding,rightPadding,topPadding 和bottomPadding 。
padding : real
control's content area and the bounds of the control 之间的均匀间距。设置此项可为leftPadding,rightPadding,topPadding, 和bottomPadding 提供默认值。每一面都可以单独覆盖。
另请参阅 leftPadding,rightPadding,topPadding 和bottomPadding 。
rightPadding : real
控件的right padding 。如果未设置,则返回padding 。
另请参阅 padding,leftPadding,topPadding 和bottomPadding 。
spacing : real
控件内部可视化元素之间的间距,例如指示器和标签之间的间距。
text : TextStyle
分组属性,用于设置控件文本标签的样式。
topPadding : real
控件的top padding 。如果未设置,则返回padding 。
另请参阅 padding,bottomPadding,leftPadding 和rightPadding 。
transition : Transition
Transition ,用于在控件进入新状态(如悬停或按下)时使样式属性产生动画。如果设置为null (默认值),则会立即应用属性更改,而不会产生动画效果。
button { background.color: "mistyrose" hovered.background.color: "plum" transition: Transition { ColorAnimation { properties: "background.color, background.shadow.color, handle.color" easing.type: Easing.OutQuad duration: 500 } NumberAnimation { properties: "background.leftRadius, background.rightRadius" easing.type: Easing.OutQuad duration: 500 } } // I only want a fade-out effect (not fade-in). So while the button // is hovered, remove the transition, so that it only applies in the // normal state. In other words, it's the state being entered that // determines the transition, not the state that is left. hovered.transition: null }
为了避免在每个委托中重复相同的目标属性,StyleKit 提供了StyleAnimation ,以方便使用,它可以代替标准动画,也可以与标准动画结合使用:
comboBox { background.color: "mistyrose" hovered.background.color: "plum" transition: Transition { StyleAnimation { animateColors: true animateBackgroundRadii: true animateIndicatorRadii: true animateBackgroundShadow: true easing.type: Easing.OutQuad duration: 500 } } }
另外请注意,ColorAnimation 有一个特殊功能,即如果property 和properties 未被设置,则在状态改变期间改变的所有颜色属性都会产生动画效果。
© 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.