CustomTheme QML Type
定义一个已命名的自定义主题。更多
| Import Statement: | import Qt.labs.StyleKit |
属性
详细说明
自定义主题可让您在light 和dark 之外添加其他主题。浅色和深色主题根据操作系统的配色方案应用于automatically ,而自定义主题则必须由应用程序明确激活。除此以外,所有主题的工作方式都是一样的。
您可以在Style 中定义任意数量的自定义主题。
Style { CustomTheme { name: "HighContrast" theme: Theme { control.background.color: "white" control.background.border.color: "black" control.background.border.width: 2 } } CustomTheme { name: "Sepia" theme: Theme { control.text.color: "#5b4636" control.background.color: "#f4ecd8" control.background.border.color: "#c8b99a" applicationWindow.background.color: "#efe6d0" } } }
要激活自定义主题,请将Style::themeName 设置为应用程序中的名称:
ComboBox { model: StyleKit.style.themeNames onCurrentTextChanged: StyleKit.style.themeName = currentText }
您还可以将自定义主题设置为启动时的默认主题:
ApplicationWindow {
width: 1024
height: 800
visible: true
StyleKit.style: MyStyleKitStyle {
themeName: "HighContrast"
}
}在运行时,可通过Style::customThemeNames 或Style::themeNames 查询样式中定义的自定义主题。
注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。
另请参阅 Theme,Style::themeName, 和Style::customThemeNames 。
属性文档
name : string
该主题的名称。这是分配给Style::themeName 的值,用于激活主题。
theme : Component
定义主题的Theme 组件。只有在激活主题时,它才会被实例化。
主题中未设置的属性将返回到Style 中定义的属性。
© 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.