1
我正在製作一個自定義的ComboBox
項目,兩邊有兩個圖標,中間有一個ComboBox
。我希望當點擊任何圖標時,會打開ComboBox
下拉菜單,但我不知道該如何操作。如何打開ComboBox下拉菜單?
這裏是我的代碼:
// ComboIcon.qml
Rectangle{
color: "#fff"
radius: 10
property alias iconSource: icon.source
property alias comboModel: combo.model
Row{
anchors.fill: parent
Item{
width: parent.width * 0.2
height: parent.height
Image{
id: icon
width: parent.width * 0.7
height: parent.height * 0.7
anchors.centerIn: parent
}
MouseArea{
anchors.fill: parent
// onClicked: combo.??
}
}
ComboBox{
id: combo
width: parent.width * 0.65
height: parent.height
style: ComboBoxStyle{
background:Rectangle {
color: "#fff"
anchors.fill: parent
}
label: Text {
height: parent.height * 0.7
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHLeft
color: "#6186da"
font.family: "SansSerif"
font.pointSize : 20
fontSizeMode: Text.Fit
text: control.currentText
}
}
}
Item{
width: parent.width * 0.15
height: parent.height
Image{
width: parent.width * 0.4
height: parent.height * 0.4
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
source: "../assets/images/combo_arrow.png"
}
MouseArea{
anchors.fill: parent
//onClicked: combo.??
}
}
}
}
我想使用類似combo.clicked()
或combo.focus = true
,但它似乎並沒有工作。任何幫助將非常感激, 謝謝。