本页内容

StyleKitDebug QML Type

追踪控件的样式属性如何被解析。更多...

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

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

属性

详细说明

StyleKitDebug 是一款诊断性应用内工具,用于将样式属性的读取操作记录到调试输出中。它有助于理解控件为何呈现特定外观,特别是在涉及多个 `themes ` 或 `style variations` 的复杂样式中。

可通过StyleKit.debug 访问该工具。

注意:此 工具尚处于实验阶段。启用它将严重降低性能,仅应用于调试。输出格式在未来的版本中可能会发生变化。

要开始追踪,请将您希望进行内省的控件赋值给control 属性:

ApplicationWindow {
    id: app
    width: 1024
    height: 800
    visible: true

    StyleKit.debug.control: someButton
    StyleKit.debug.filter: "background.color"

    StyleKit.style: Style {
        button {
            background.color: "gray"
            hovered.background.color: "dimgray"
        }
        dark: Theme {
            button {
                background.color: "skyblue"
                hovered.background.color: "lightblue"
            }
        }
    }

    Column {
        anchors.fill: parent
        anchors.margins: 10
        spacing: 10

        Button {
            id: someButton
            text: "A Button"
        }
    }
}

每个解析后的属性都会以单行形式输出,显示该值的来源及其解析结果:

[read] StyleReader[Hovered].button.background.color -> Style.Theme(Dark).button[Hovered] = #add8e6

输出中的 `StyleReader ` 指的是 `Button ` 内部用于读取其样式属性值的 `StyleReader `。

追踪StyleReader 的属性读取操作可能会产生大量输出。请使用filter 将输出范围限定在感兴趣的属性上。

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

另请参阅 StyleKit::debug 和StyleKit 属性解析。

属性文档

control : Item

要追踪的Control 或StyleReader 的ID。

设置此选项后,StyleKit 会将该项的所有样式属性读取操作记录到调试输出中。将其设置为null 可停止跟踪。

另请参阅 filter 。

filter : string

用于过滤调试输出的正则表达式。仅打印与该模式匹配的行。默认情况下,会显示所有输出。

例如,若要仅追踪背景颜色:

StyleKit.debug.filter: "background.color"

若要追踪所有背景颜色,包括诸如background.color 、background.border.color 、background.image.color 和background.shadow.color 等属性,请使用以下正则表达式:

StyleKit.debug.filter: "background.*color"

另请参阅 control 。

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