ItemDelegate QML Type

Basic item delegate that can be used in various views and controls. 更多...

import 语句: import QtQuick.Controls
继承:

AbstractButton

继承者:

CheckDelegate , RadioDelegate , SwipeDelegate , SwitchDelegate ,和 TreeViewDelegate

特性

详细描述

ItemDelegate presents a standard view item. It can be used as a delegate in various views and controls, such as ListView and ComboBox .

ItemDelegate inherits its API from AbstractButton . For instance, you can set text , display an icon , and react to clicks 使用 AbstractButton API.

ListView {
    width: 160
    height: 240
    model: Qt.fontFamilies()
    delegate: ItemDelegate {
        text: modelData
        width: parent.width
        onClicked: console.log("clicked:", modelData)
        required property string modelData
    }
    ScrollIndicator.vertical: ScrollIndicator { }
}
					

另请参阅 Customizing ItemDelegate and 委托控件 .

特性文档编制

highlighted : bool

This property holds whether the delegate is highlighted.

A delegate can be highlighted in order to draw the user's attention towards it. It has no effect on keyboard interaction. For example, you can highlight the current item in a ListView using the following code:

ListView {
    id: listView
    model: 10
    delegate: ItemDelegate {
        text: index
        highlighted: ListView.isCurrentItem
        required property int index
        onClicked: listView.currentIndex = index
    }
}
					

默认值为 false .