在Qt给的ComboBox由于没有限定下拉框的长度,数据量多时下拉框可以到达软件的底部,比较影响使用,这里可以对其样式进行修改,设置__maxPopupHeight的值即可。
ComboBox {
id: province_company_check
anchors.fill: parent
model: ListModel {
id: province_company_model
}
style:ComboBoxStyle {
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 250
__menuItemType: "comboboxitem"
frame: Rectangle { // MenuStyle background
border.width: 1
}
itemDelegate.label: // an item text
Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
color: styleData.selected ? "white" : "black"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
color: styleData.selected ? "#3199e8" : "transparent"
}
__scrollerStyle: ScrollViewStyle { }
}
}
Connections {
target: province_company_check.__popup
onAboutToHide: {
province_company_check.__popup.__destroyAllMenuPopups()
}
}
}