QML中使用ComboBox时,下拉框的风格怎么设置? 还有就是下拉框的高度怎么设置,当我添加的项过多时就会超出整个界面的高度,很是苦恼啊
------解决思路----------------------
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
Item{
ComboBox {
id: box
currentIndex: 2
width: 100
height: 20
anchors.centerIn: parent
activeFocusOnPress: true
style: ComboBoxStyle {
id: comboBox
background: Rectangle {
id: rectCategory
radius: 2
border.width: 1
color: "#fff"
}
label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 10
font.family: "微软雅黑"
font.capitalization: Font.SmallCaps
color: "black"
text: control.currentText
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 200
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#00ffffff"
border.width: 0
radius: 0
}
itemDelegate.label:Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 12
font.family: "微软雅黑"
font.capitalization: Font.SmallCaps
color: styleData.selected ? "white" : "black"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
radius: 0
color: styleData.selected ? "darkGray" : "transparent"
}
__scrollerStyle: ScrollViewStyle { }
}
}
model: ListModel {
id: cbItems
ListElement { text: "香蕉" }
ListElement { text: "苹果" }
ListElement { text: "椰子" }
ListElement { text: "橘子" }
ListElement { text: "葡萄" }
}
}
}