我希望在ComboBox中具有与ListView (分段ListView示例)相同的部分功能。
但是我在ComboBox里找不到这样的东西。
这有可能吗?
发布于 2017-06-30 16:00:43
为了在ListView中具有与ComboBox相同的部分功能,您可以简单地在ComboBox中包含一个ListView。
基本上可以自定义所有Quick 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 { }
}
}
}它是这样呈现的:

https://stackoverflow.com/questions/44849497
复制相似问题