我想在我的項目中使用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