本页内容

ItemDelegate QML Type

可在各种视图和控件中使用的基本项委托。更多...

属性

详细说明

ItemDelegate 提供了一个标准的视图项。它可作为委托用于各种视图和控件中,例如ListView 和ComboBox 。

ItemDelegate 的 API 继承自 `AbstractButton`。例如,您可以使用 `AbstractButton ` API 设置 `text`、显示图标,并响应 `clicks ` 事件。

ListView {
    id: listView
    width: 160
    height: 240

    model: Qt.fontFamilies()

    delegate: ItemDelegate {
        text: modelData
        width: listView.width
        onClicked: console.log("clicked:", modelData)

        required property string modelData
    }

    ScrollIndicator.vertical: ScrollIndicator { }
}

另请参阅 “自定义 ItemDelegate和Delegate 控件”。

属性文档

highlighted : bool

该属性用于控制委托是否被高亮显示。

可以对委托进行高亮显示,以吸引用户的注意力。这不会影响键盘交互。例如,您可以使用以下代码在ListView 中将当前项目高亮显示:

ListView {
    id: listView
    model: 10
    delegate: ItemDelegate {
        text: index
        highlighted: ListView.isCurrentItem

        required property int index

        onClicked: listView.currentIndex = index
    }
}

默认值为 `false`。

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