本页内容

IndicatorStyle QML Type

定义控件指示器的样式。更多内容...

Import Statement: import Qt.labs.StyleKit
Inherits:

DelegateStyle

Status: Technology preview

此类型处于技术预览阶段,可能会有变动。

属性

详细说明

IndicatorStyle 继承自DelegateStyle ,并增加了用于指示器样式设置的特定属性。

IndicatorStyle 本身描述指示器的背景,而foreground 则描述其中绘制的内容。例如,checkBox.indicator 用于设置复选框边框的样式,而checkBox.indicator.foreground 用于设置复选标记的样式。对于switchControl 、slider 和progressBar ,指示器用于设置凹槽样式,而前景则用于设置填充样式。

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 同时具有增量和减量按钮。可通过first 和second 子指示器、spinBox.indicator.first 以及spinBox.indicator.second 分别对其进行样式设置。对于SpinBox ,indicator.first 用于设置增量按钮的样式,而indicator.second 用于设置减量按钮的样式。未在子指示器上设置的属性将回退到指示器本身。

注意: 出于向后兼容性考虑,up 和down 属性仍 作为first 和second 的别名保留。新代码应使用first 和second ,因为这些名称更具通用性,可用于不代表增减操作的带子指示器的控件。这些兼容性别名可能会在未来版本中被移除。

spinBox {
    text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
    padding: 0
    indicator {
        fillHeight: true
        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"
            width: 10
            height: 10
            alignment: Qt.AlignCenter
        }
        // up button
        first {
            alignment: Qt.AlignRight
            foreground.rotation: -90
        }
        // down button
        second {
            alignment: Qt.AlignLeft
            foreground.rotation: 90
        }
    }
}

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

另请参阅 SubIndicatorStyle 、DelegateStyle 、ControlStyle 、ControlStateStyle 以及FallbackStyle 参考文档。

属性文档

first : SubIndicatorStyle

用于为显示多个指示器的控件中的第一个子指示器设置样式的分组属性。对于SpinBox ,该属性用于设置增量按钮的样式。未设置的属性将回退到指示器本身的样式。

注意: 出于向后兼容性考虑, up 属性仍 作为first 的别名保留。新代码应使用first ,因为该名称更具通用性,可适用于子指示器不代表“向上”操作的控件。该兼容性别名可能会在未来版本中被移除。

另请参阅 second 。

foreground : DelegateStyle

用于设置该指示器前景色元素样式的分组属性。例如,checkBox.indicator 描述复选框边框,而checkBox.indicator.foreground 则描述复选标记。

对于诸如slider 、progressBar 和switchControl 之类的控件,indicator.foreground 代表进度轨迹或凹槽内的填充部分,而indicator 本身则代表凹槽。

second : SubIndicatorStyle

用于设置样式(例如SpinBox )中第二个子指示器的分组属性。未设置的属性将回退到指示器本身。

注意: 出于向后兼容性考虑, down 属性仍 作为second 的别名保留。新代码应使用second ,因为该名称更具通用性,可用于子指示器不代表下拉操作的控件。该兼容性别名可能会在未来版本中被移除。

另请参阅 first 。

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