在本页

IndicatorStyle QML Type

定义控件指示符的样式。更多

Import Statement: import Qt.labs.StyleKit
Inherits:

DelegateStyle

属性

详细说明

IndicatorStyle 对DelegateStyle 进行了扩展,其属性专门用于为指示器设计样式。

IndicatorStyle 本身描述的是指示器背景,而foreground 描述的是指示器内部绘制的内容。例如,checkBox.indicator 是复选框框架样式,checkBox.indicator.foreground 是复选标记样式。对于switchControlsliderprogressBar ,指示符样式为凹槽,前景样式为填充。

checkBox {
    background.visible: false
    text.alignment: Qt.AlignVCenter | Qt.AlignLeft
    indicator {
        color: "transparent"
        border.width: 1
        foreground {
            color: "transparent"
            image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png"
            // Hide the checkMark when the CheckBox is unchecked
            visible: false
        }
    }
    checked {
        // Show the checkMark when the CheckBox is checked
        indicator.foreground.visible: true
    }
}

有些控件有不止一个指示符。例如,SpinBox 有一个递增和递减按钮。可以使用updown 子指示器、spinBox.indicator.upspinBox.indicator.down 对它们进行独立样式设置。未在子指标上设置的属性将返回到指标本身。

spinBox {
    text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
    padding: 0
    indicator {
        implicitHeight: Style.Stretch
        color: "navy"
        opacity: 0.1
        foreground {
            color: "transparent"
            margins: 10
            image.color: "navy"
            image.fillMode: Image.PreserveAspectFit
            image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/arrow-indicator.png"
            implicitWidth: 10
            implicitHeight: 10
            alignment: Qt.AlignCenter
        }
        down {
            alignment: Qt.AlignLeft
            foreground.rotation: 90
        }
        up {
            alignment: Qt.AlignRight
            foreground.rotation: -90
        }
    }
}

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

另请参阅 SubIndicatorStyle,DelegateStyle,ControlStyle,ControlStateStyleFallbackStyle Reference

属性文档

down : SubIndicatorStyle

分组属性,用于设计向下(递减)子指标的样式。该属性用于SpinBox 等控件。未设置属性会返回到指标本身。

另请参阅 up

foreground : DelegateStyle

分组属性,用于设计该指示符前景元素的样式。例如,checkBox.indicator 描述复选框框架,而checkBox.indicator.foreground 是复选标记。

对于sliderprogressBarswitchControl 等控件,indicator.foreground 表示凹槽内的进度轨迹或填充,而indicator 本身表示凹槽。

up : SubIndicatorStyle

分组属性,用于向上(递增)子指标的样式设计。该属性由SpinBox 等控件使用。未设置属性会返回到指标本身。

另请参阅 down

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