我想在我的项目中使用ComboBox
类型。是否可以更改下拉菜单的外观(颜色,形状,文本样式),还是需要使用矩形组合,ListView
和其他类型?QML组合框项目DropDownMenu样式
下面的代码应用自定义,但没有修改对于这仍然灰色的下拉菜单来定义:
ComboBox {
currentIndex: 2
activeFocusOnPress: true
style: ComboBoxStyle {
id: comboBox
background: Rectangle {
id: rectCategory
radius: 5
border.width: 2
color: "#fff"
Image {
source: "pics/corner.png"
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.bottomMargin: 5
anchors.rightMargin: 5
}
}
label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 15
font.family: "Courier"
font.capitalization: Font.SmallCaps
color: "black"
text: control.currentText
}
}
model: ListModel {
id: cbItems
ListElement { text: "Banana" }
ListElement { text: "Apple" }
ListElement { text: "Coconut" }
}
width: 200
}
我刚刚测试此代码在Mac OS X 10.9,并想知道,它不是为我工作。你可以建议我一些OS X相关的编辑,使其工作。尽管如此,在Windows平台上一切都很好。 – 2015-01-19 16:53:28
那么,我当时只在Windows/Android上试过这个代码,对不起。 :) 你可以检查Qt安装中的qml样式文件(搜索像qml/QtQuick/Controls/Styles/Desktop这样的子路径)来查看w.r.t的变化。 Windows并尝试修改解决方案。 在我身边,我会测试我的Mac上的代码,以提供解决这个特定问题的编辑(显然,因为我有空闲时间)。 – BaCaRoZzo 2015-01-19 17:16:40
这非常有帮助!谢谢! – 2016-01-21 09:49:34