qml combobox美化
时间: 2023-12-04 08:04:39 浏览: 162
以下是一些QML ComboBox美化的方法:
1.更改下拉箭头的颜色和样式:
```qml
ComboBox {
id: control
width: 200
height: 32
model: [qsTr("Fade in"), qsTr("Fade out"), qsTr("Slide")]
indicator: Rectangle {
width: 10
height: 10
color: "#333"
rotation: control.expanded ? 180 : 0
}
}
```
2.更改下拉列表的背景颜色和样式:
```qml
ComboBox {
id: control
width: 200
height: 32
model: [qsTr("Fade in"), qsTr("Fade out"), qsTr("Slide")]
delegate: ItemDelegate {
width: control.width
text: model.display
highlighted: control.highlightedIndex === index
background: Rectangle {
color: highlighted ? "#ccc" : "#fff"
}
}
}
```
3.更改选中项的背景颜色和样式:
```qml
ComboBox {
id: control
width: 200
height: 32
model: [qsTr("Fade in"), qsTr("Fade out"), qsTr("Slide")]
delegate: ItemDelegate {
width: control.width
text: model.display
highlighted: control.highlightedIndex === index
background: Rectangle {
color: highlighted ? "#ccc" : "#fff"
}
contentItem: Text {
text: model.display
color: highlighted ? "#fff" : "#000"
font.bold: highlighted
}
}
}
```
阅读全文