本页内容

ShadowStyle QML Type

定义委托的阴影样式。更多内容...

Import Statement: import Qt.labs.StyleKit
Status: Technology preview

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

属性

详细说明

ShadowStyle 提供了一系列属性,用于在DelegateStyle 控件后方渲染投影。该属性以shadow 分组属性的形式,可在任何委托上使用。

button {
    background {
        shadow {
            color: "lightgray"
            opacity: 0.6
            verticalOffset: 2
            horizontalOffset: 2
        }
    }
}

通过调整缩放比例和颜色,阴影还可以用来创建发光效果。以下代码片段为Switch 的控件柄添加了漫射白色光晕,当选中时光晕会变强:

dark: Theme {
    applicationWindow.background.color: "#1e1e1e"
    switchControl {
        handle.color: "white"
        handle.shadow {
            color: "ghostwhite"
            scale: 1.2
            opacity: 0.6
        }
        checked.handle.shadow.scale: 1.5
    }
}

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

另请参阅 DelegateStyle 、ControlStyle 、ControlStateStyle 以及《FallbackStyle 参考》。

属性文档

blur : real

阴影的模糊程度。当值设为0.0 时,会生成锐利的阴影;而较大的值则会生成更柔和、更漫射的阴影。默认值为10.0 。

color : color

阴影的颜色。默认值为transparent ,这意味着默认情况下不会绘制阴影。

另请参阅 visible 和opacity 。

delegate : Component

一个自定义的 QMLComponent ,用于替换默认的阴影渲染效果。启用后,StyleKit 会实例化此组件,而不是绘制默认的阴影。

horizontalOffset : real

委托对象投射的阴影的水平偏移量,单位为像素。

opacity : real

阴影的不透明度,范围从0.0 (完全透明)到1.0 (完全不透明)。默认值为1.0 。

另请参阅 visible 和color 。

scale : real

阴影相对于代理对象的缩放因子。默认值为1.0 。

verticalOffset : real

委托对象投射的阴影的垂直偏移量,单位为像素。

visible : bool

是否显示阴影。默认值为true 。

但是,由于默认阴影color 的颜色为transparent ,除非设置了其他颜色,否则阴影将不可见。

另请参阅 opacity 。

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