在本页

ControlStyle QML Type

定义normal 状态下控件的样式。更多

Import Statement: import Qt.labs.StyleKit
Inherits:

ControlStateStyle

Inherited By:

CustomControl

属性

详细描述

ControlStyle 描述了Control 的样式。它的 API 与Qt Quick 控件的 API 基本相同:它为background,indicator,handle, 和text 等委托提供分组属性,以及paddingspacing 等布局属性。如果您熟悉Qt Quick 控件中Control 的 API,您会发现 ControlStyle API 很容易掌握。

ControlStyle 继承了ControlStateStyle ,因为它代表正常状态:直接在 ControlStyle 上设置的属性描述了控件在没有其他状态活动时的外观。特定于状态的重载是通过嵌套状态设置的,如hovered pressed , 和checked

Each stylable controlStyleThemeStyleVariation 中,ControlStyle 是一个控件样式。例如,在下面的代码段中,control,buttonradioButton 都是 ControlStyle:

Style {
    control {
        padding: 6
        text {
            color: "white"
        }
        background {
            radius: 4
            border.color: "gray"
        }
        indicator {
            implicitWidth: 20
            implicitHeight: 20
            border.width: 1
        }
        handle {
            implicitWidth: 20
            implicitHeight: 20
            radius: 10
        }
    }

    button {
        background {
            implicitWidth: 120
            shadow.opacity: 0.6
            shadow.verticalOffset: 2
            shadow.horizontalOffset: 2
            shadow.color: "gray"
            color: "lightsteelblue"
            gradient: Gradient {
                GradientStop { position: 0.0; color: Qt.alpha("black", 0.0)}
                GradientStop { position: 1.0; color: Qt.alpha("black", 0.2)}
            }
        }
        hovered {
            background.color: "lightslategrey"
        }
        pressed {
            background.scale: 0.95
        }
    }

    radioButton {
    }

    checkBox {
    }

    slider {
    }

    // etc...
}

另请参阅 All stylable controls,Style,Theme,StyleVariation,ControlStateStyleDelegateStyle

属性文档

variations : list<StyleVariation>

该控件类型的type variations 列表。

类型变体为该控件类型的子控件(或后代控件)提供备用样式。例如,您可以用它为frame 内的所有buttons 和其他地方的按钮设计不同的样式:

Style {
    frame {
        variations: StyleVariation {
            button {
                text.color: "ghostwhite"
                background.border.width: 0
                background.color: "slategrey"
            }
        }
    }

    groupBox {
        // groupBox falls back to frame. Therefore, if the varations set on a
        // frame is not wanted on a groupBox, just override it and set it back to [].
        variations: []
    }
}

与通过StyleVariation::variations 附加属性从应用程序应用于特定控件实例的实例变体不同,类型变体从Style 应用于控件类型的所有实例,而无需应用程序选择加入。

另请参见 StyleVariation

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