答案 0 :(得分:7)
为了在ListView
中拥有与ComboBox
相同的版块功能,您只需在ListView
中添加ComboBox
。
您可以自定义所有Qt Quick Controls 2,以下是ComboBox
的示例:https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox
在您的情况下,您需要自定义popup
属性以包含已启用部分的ListView
。
我写了一个例子:
ComboBox {
id: control
width: 200
model : ["Albert Dupontel","Antoine Griezmann","Peter Sagan","Rodney Mullen","Serena Williams"]
popup: Popup {
y: control.height
width: control.width
implicitHeight: Math.min(contentItem.implicitHeight, 300)
padding: 0
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
section.property: "modelData"
section.criteria: ViewSection.FirstCharacter
section.delegate: Label {
x: 10
text: section
}
ScrollIndicator.vertical: ScrollIndicator { }
}
}
}
它呈现如下: