在本页

AbstractStylableControls QML Type

抽象基本类型,包含可进行样式化的控件类型。更多

Import Statement: import Qt.labs.StyleKit
Inherited By:

AbstractStyle, Style, StyleVariation, and Theme

属性

详细说明

AbstractControls 是一种抽象的基本类型。它包含每个控件类型的ControlStyle ,可通过StyleThemeStyleVariation 进行样式设置。

控件类型形成了一个层次结构,其中在基础类型上设置的属性会向下传播到更具体的类型。例如,为abstractButton.background.radius 指定一个半径为 4 的属性,会使所有按钮类型(如buttoncheckBoxradioButton )的半径都变为 4。

本页的代码段展示了可用于样式化每种控件类型的一些关键属性,但这些属性并不详尽。如ControlStyleDelegateStyle 文档所述,还有许多其他属性可用。实际上,其中一些属性也可以省略,因为fallback style 已经提供了合理的默认值。这意味着,如果您简单地从某个片段中移除某个属性,实际上可能不会影响其外观,因为它只是从回退样式中读取。

注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。

属性文档

abstractButton : ControlStyle

分组属性,用于设置所有类按钮控件的样式,包括Button,CheckBox,RadioButton, 和Switch 。未设置的属性返回到control

abstractButton.background.radius: 4 // all buttons get a radius of 4
checkBox.indicator.radius: 2 // except check boxes, which get a radius of 2

另请参阅 "控件类型"。

applicationWindow : ControlStyle

用于设置样式的分组属性ApplicationWindow

未设置的属性将返回control

使用applicationWindow 设置窗口的背景颜色:

light: Theme {
    applicationWindow.background.color: "#f0f0f0"
}
dark: Theme {
    applicationWindow.background.color: "#404040"
}

注意: 应用程序需要使用ApplicationWindow 而不是 Window 才能生效。

button : ControlStyle

用于设置样式的分组属性Button

未设置的属性返回abstractButton

button {
    background {
        implicitWidth: 120
        implicitHeight: 40
        shadow {
            opacity: 0.6
            color: "gray"
            verticalOffset: 2
            horizontalOffset: 2
        }
        color: "cornflowerblue"
        gradient: Gradient {
            // The gradient is drawn on top of the 'background.color', so
            // we use semi-transparent stops to give the button some shading
            // while letting the base color show through. This makes it easier
            // to change the color, but keep the shading, in the hovered state below.
            GradientStop { position: 0.0; color: Qt.alpha("black", 0.0)}
            GradientStop { position: 1.0; color: Qt.alpha("black", 0.2)}
        }
    }
    text.color: "white"
    hovered.background.color: "royalblue"
    pressed.background.scale: 0.95
}

checkBox : ControlStyle

用于设置样式的分组属性CheckBox

未设置的属性返回abstractButton

checkBox {
    // Hide the button background; show only the indicator and text
    background.visible: false

    indicator {
        color: "white"
        border.color: "darkslategray"
        foreground {
            color: "transparent"
            image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png"
            image.color: palette.accent

            // Hide the checkmark when the checkbox is not checked
            visible: false
        }
    }

    // Show the checkmark when the checkbox is checked
    checked.indicator.foreground.visible: true
}

comboBox : ControlStyle

用于设置样式的分组属性ComboBox

未设置的属性返回control

comboBox {
    text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
    background.topLeftRadius: 4
    background.topRightRadius: 4

    indicator {
        // Show only the dropdown arrow, not the indicator background
        color: "transparent"
        border.width: 0
        foreground {
            image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/drop-indicator.png"
            image.color: "black"
        }
    }
}

control : ControlStyle

用于设置所有控件样式的分组属性。

control 是控件层次结构中的基本类型,此处设置的属性是所有其他控件类型的默认值。例如,设置control.implicitWidth: 200 可使所有控件(包括按钮、滚动指示器和其他所有控件)的宽度达到 200 像素。它还会覆盖从样式层次结构中更高层(ThemeStyleStylefallbackStyle )继承的任何值,包括悬停效果和其他基于状态的行为。请谨慎使用control ,并尽可能选择更具体的基本类型,如abstractButtonpane

control {
    padding: 8
    background.radius: 4
}

flatButton : ControlStyle

分组属性,用于为平面按钮(正常状态下无可见背景的按钮)设计样式。如果Button.flat 设置为true ,则样式将对Button 生效。

未设置的属性将返回abstractButton

flatButton {
    // Hide background normally, show on hover
    background.visible: false
    hovered.background.visible: true
}

frame : ControlStyle

用于设置样式的分组属性Frame

未设置的属性返回pane

frame {
    background {
        color: "#fafafa"
        border.color: "#d0d0d0"
        radius: 4
    }
}

groupBox : ControlStyle

用于设置样式的分组属性GroupBox

未设置的属性返回frame

groupBox {
    // A group box is a container for other controls, so we give it some
    // padding to avoid the child controls to be too close to the border
    padding: 20

    // Move the label to the right, to match the radius of the background
    text.leftPadding: 6
    text.color: "darkslategray"

    background {
        // Move the frame down, below the text label
        topMargin: 30
        radius: 6
        color: "#f8f8f8"
        border.color: "#d0d0d0"
    }
}

itemDelegate : ControlStyle

用于设置样式的分组属性ItemDelegate

未设置的属性返回control

注: Qt Quick 控件中,ItemDelegate 继承自AbstractButton 。但在StyleKit 中,itemDelegate 则继承自control ,而不是abstractButton ,因为委托的样式通常与按钮截然不同(扁平、无边框或阴影等)。

itemDelegate {
    text.alignment: Qt.AlignVCenter | Qt.AlignLeft
    background {
        radius: 0
        color: "white"
        border.width: 0
    }
    hovered.background.color: "#f0f0f0"
}

label : ControlStyle

用于设置样式的分组属性Label

未设置的属性返回control

light: Theme {
    // Labels typically have no background, so set background.visible to false.
    // Alternatively, hiding the background for labels can be done once for all
    // themes by setting Style.label.background.visible: false.
    label.background.visible: false
    label.text.color: "black"
}
dark: Theme {
    label.background.visible: false
    label.text.color: "white"
}

page : ControlStyle

用于设置样式的分组属性Page

未设置的属性返回pane

page {
    background {
        color: "white"
        border.width: 0
    }
}

pane : ControlStyle

用于设置样式的分组属性Pane

未设置的属性返回control

pane {
    background {
        implicitWidth: 200
        implicitHeight: 200
        color: "white"
    }
}

用于设置样式的分组属性Popup

未设置的属性返回control

popup {
    background {
        color: "white"
        border.width: 1
        border.color: "darkslategray"
        radius: 4
    }
}

progressBar : ControlStyle

用于设计ProgressBar 风格的分组属性。对于进度条,槽的样式是通过指示符来设计的,而进度轨的样式是通过指示符的前景来设计的。

未设置的属性将返回control

progressBar {
    // Hide the background; show only the progress bar
    background.visible: false
    indicator {
        implicitWidth: 150
        implicitHeight: 8
        radius: 4
        color: "#e0e0e0"
        foreground {
            // Set margins to add some space between the progress track and the groove
            margins: 2
            color: palette.accent
            radius: 4
        }
    }
}

StyleKit 但是,《ASP.NET》并没有为进度条的不确定动画样式提供专用属性。要更改动画,您需要实现一个自定义的指示器前景delegate

progressBar {
    indicator {
        implicitWidth: 150
        implicitHeight: 8
        foreground {
            delegate: StyledItem {
                // Draw a pulsating progress track when in indeterminate mode, and a normal track otherwise
                width: control.indeterminate ? parent.width : parent.width * control.visualPosition
                height: parent.height
                opacity: control.indeterminate ? 0.1 : 1.0
                SequentialAnimation on opacity {
                    running: control.indeterminate
                    loops: Animation.Infinite
                    NumberAnimation { from: 0.1; to: 1.0; duration: 500; easing.type: Easing.InOutQuad }
                    NumberAnimation { from: 1.0; to: 0.1; duration: 500; easing.type: Easing.InOutQuad }
                }
            }
        }
    }
}

radioButton : ControlStyle

用于设置样式的分组属性RadioButton

未设置的属性返回abstractButton

radioButton {
    // Hide the button background; show only the indicator and text
    background.visible: false

    indicator {
        // Make the indicator circular
        radius: 255
        foreground {
            // The foreground circle is what shows the checked state, so we make
            // it a bit smaller than the outer circle by setting margins
            margins: 4
            radius: 255
            // Hide the foreground circle when the radio button is not checked
            visible: false
        }
    }

    // Show the foreground circle when the radio button is checked
    checked.indicator.foreground.visible: true
}

scrollBar : ControlStyle

用于设计ScrollBar 风格的分组属性。对于滚动条,槽的样式是通过指示符来设计的,而柄的样式是通过指示符的前景来设计的。

未设置的属性将返回control

scrollBar {
    padding: 0
    background {
        // For scroll bars, we typically don't want a background, only a
        // draggable indicator and a groove.
        visible: false
        // Note: even if the background is hidden, its implicit size is still used to
        // determine the overall size of the scroll bar. So we set implicitHeight equal to
        // the height of the indicator, to make it appear on the side of, and not on top
        // of, the content area in a ScrollView. For a horizontal scroll bar, on the other
        // hand, the width is automatically set by the view to match its own width.
        implicitHeight: 10
    }
    indicator {
        radius: 255
        // For horizontal scroll bars, we only set the height. The width is set by the
        // view to be the relative size of the view's content that is currently visible.
        implicitHeight: 10
        color: "#c0c0c0"
        foreground.visible: false
    }
    vertical {
        // Override properties for vertical scroll bars if needed.
        // For vertical indicators, we only set width. The height is set by the
        // view to be the relative size of the view's content that is currently visible.
        indicator.implicitWidth: 10
        background.implicitWidth: 10
    }
}

scrollIndicator : ControlStyle

用于设置样式的分组属性ScrollIndicator

未设置的属性返回control

scrollIndicator {
     // For scroll indicators, we typically don't want a background, only a
     // sliding indicator
    background.visible: false
    indicator {
        // For horizontal indicators, we only set the height. The width is set by the
        // view to be the relative size of the view's content that is currently visible.
        implicitHeight: 5
        border.width: 0
        color: "cornflowerblue"
        // The indicator is so simple that it doesn't need a foreground
        foreground.visible: false
    }
    vertical {
        // Override properties for vertical scroll indicators if needed
        indicator.color: "violet"
        // For vertical indicators, we only set width. The height is set by the
        // view to be the relative size of the view's content that is currently visible.
        indicator.implicitWidth: 5
    }
}

scrollView : ControlStyle

分组属性,用于设计ScrollView.NET 风格。

ScrollView 其本身没有可视化代表样式。其滚动条可通过scrollBar 属性单独设置样式。但您可以使用padding 来控制滚动条与内容区域之间的空间。

未设置的属性会返回到control.

scrollView {
    // Add some space between the scroll bars and the content area
    padding: 2
    // For the sake of the example, style the scroll bars in a ScrollView
    // differently from the default scroll bars by using a StyleVariation.
    variations: StyleVariation {
        scrollBar.indicator.color: "cornflowerblue"
    }
}

slider : ControlStyle

用于设计Slider 风格的分组属性。对于滑动条,槽的样式是通过指示器设计的,而进度轨迹的样式是通过指示器的前景设计的。未设置的属性将返回control

slider {
    background.visible: false

    indicator {
        // The groove of the slider should fill out the entire width of
        // the control, which we achieve by setting implicitWidth to Style.Stretch.
        implicitWidth: Style.Stretch
        implicitHeight: 8
        radius: 255
        color: "#e0e0e0"
        foreground {
            radius: 255
            color: palette.accent
        }
    }

    handle {
        implicitWidth: 24
        implicitHeight: 24
        radius: 255
        color: "white"
        border.color: "#c0c0c0"
    }

    vertical {
        // if needed, you can override properties for vertical sliders
    }
}

spinBox : ControlStyle

用于设置样式的分组属性SpinBox

未设置的属性将返回control

spinBox {
    // Center the text between the up/down buttons
    text.alignment: Qt.AlignHCenter | Qt.AlignVCenter

    indicator {
        color: "transparent"
        border.width: 0
        foreground {
            image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/arrow-indicator.png"
            image.color: "black"
            alignment: Qt.AlignCenter
        }
        // Place the down and up buttons on the left and right side of the control
        down {
            alignment: Qt.AlignLeft
            foreground.rotation: 90
        }
        up {
            alignment: Qt.AlignRight
            foreground.rotation: -90
        }
    }
}

注意: 目前只能将上下按钮定位在控件的左侧或右侧,而不能定位在彼此的顶部。

switchControl : ControlStyle

用于设置样式的分组属性Switch

未设置的属性返回abstractButton

switchControl {
    // For a switch control, we typically don't want a background, only an indicator with a handle
    background.visible: false
    indicator {
        radius: 12
        foreground {
            // Add some space between the indicator and the foreground track
            margins: 2
            radius: 12
            // The foreground track should only be visible when the switch is checked
            visible: false
        }
    }
    checked.indicator.foreground.visible: true
    handle {
        // Add some space between the handle and the indicator
        leftMargin: 2
        rightMargin: 2
        implicitWidth: 20
        implicitHeight: 20
        radius: 255
        color: "white"
    }
}

tabBar : ControlStyle

用于设置样式的分组属性TabBar

未设置的属性返回pane

tabBar {
    padding: 0
    spacing: -1 // let tab buttons overlap slightly
    background {
        color: "white"
        border.width: 0
    }
}

tabButton : ControlStyle

用于设置样式的分组属性TabButton

未设置的属性返回abstractButton

tabButton {
    background {
        radius: 0
        topLeftRadius: 4
        topRightRadius: 4
        color: "#e8e8e8"
    }
    checked.background.color: "white"
}

textArea : ControlStyle

用于设置样式的分组属性TextArea

未设置的属性返回textInput

textArea {
    // Add some space between the text and the border of the text area
    padding: 8
    text.color: "black"
    background {
        color: "white"
        border.color: "#c0c0c0"
    }
    focused.background.border.color: palette.accent
}

textField : ControlStyle

用于设置样式的分组属性TextField

未设置的属性返回textInput

textField {
    // Add some space between the text and the border of the text field
    padding: 8
    text.alignment: Qt.AlignVCenter
    background {
        implicitWidth: 150
        color: "white"
        border.color: "#c0c0c0"
    }
    focused.background.border.color: palette.accent
}

textInput : ControlStyle

分组属性,用于设置所有文本输入控件的样式,包括TextFieldTextArea

未设置的属性将返回control

textInput {
    // Add some space between the text and the border of the text input
    padding: 8
    text.color: "black"
    background {
        color: "white"
        border.width: 1
        border.color: "#c0c0c0"
    }
}

toolBar : ControlStyle

用于设置样式的分组属性ToolBar

未设置的属性返回pane

toolBar {
    spacing: 2
    background {
        radius: 0
        implicitHeight: 40
        border.width: 1
    }
}

toolButton : ControlStyle

用于设置样式的分组属性ToolButton

未设置的属性返回abstractButton

toolButton {
    background.radius: 0
}

toolSeparator : ControlStyle

用于设置样式的分组属性ToolSeparator

未设置的属性返回control

toolSeparator {
    background.visible: false
    indicator {
        implicitWidth: 30
        implicitHeight: 1
        border.width: 0
        color: "#c0c0c0"
        foreground.visible: false
    }
    vertical {
        // Override properties for vertical tool separators if needed.
        // Note: Qt Quick Controls automatically swaps the width and height
        // for vertical tool separators, so avoid doing that here.
    }
}

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