Qt控件之自定义ComboBox样式

来源:互联网 发布:mac 安装beego 编辑:程序博客网 时间:2024/05/21 11:37

在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()        }    }}
原创粉丝点击