ItemDelegate QML Type

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

Import Statement: import QtQuick.Controls 2.2
开始支持版本: Qt 5.7
基类:

AbstractButton

派生类:

CheckDelegate, RadioDelegate, SwipeDelegate, and SwitchDelegate

属性

详细描述

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, and react to clicks using the AbstractButton API.


  ListView {
      width: 160
      height: 240

      model: Qt.fontFamilies()

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

      ScrollIndicator.vertical: ScrollIndicator { }
  }

参见 Customizing ItemDelegate and Delegate Controls.

属性

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: modelData
          highlighted: ListView.isCurrentItem
          onClicked: listView.currentIndex = index
      }
  }

The default value is false.