Properties
acceptableInput : bool
count : int //組合框中的數(shù)量
currentIndex : int //當(dāng)前索引
currentText : string //當(dāng)前項(xiàng)的文本
delegate : Component //委托
displayText : string //文本string顯示在組合框中
down : bool //是否為下拉
editText : string //可編輯組合框的文本字段中的文本
editable : bool //編輯框字段是否可編輯(默認(rèn)false)
flat : bool //按鈕框是否為平面
highlightedIndex : int //突出顯示項(xiàng)的索引
indicator : Item //下拉指示器項(xiàng)
inputMethodComposing : bool //可編輯組合框是否具有輸入方法的部分文本輸入
inputMethodHints : flags //為輸入提供模板(預(yù)期內(nèi)容)
model : model //數(shù)據(jù)模型
popup : Popup //彈出窗口
pressed : bool //是否按下按下組合框按鈕
textRole : string //填充組合框模型角色
validator : Validator //可編輯組合框的輸入文本驗(yàn)證器
import QtQuick 2.6
import QtQuick.Controls 2.1
ComboBox {
id: control
model: ["First", "Second", "Third"]
delegate: ItemDelegate {
width: control.width
contentItem: Text {
text: modelData
color: "#21be2b"
font: control.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: control.highlightedIndex === index
}
indicator: Canvas {
id: canvas
x: control.width - width - control.rightPadding
y: control.topPadding + (control.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
target: control
onPressedChanged: canvas.requestPaint()
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = control.pressed ? "#17a81a" : "#21be2b";
context.fill();
}
}
contentItem: Text {
leftPadding: 0
rightPadding: control.indicator.width + control.spacing
text: control.displayText
font: control.font
color: control.pressed ? "#17a81a" : "#21be2b"
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 120
implicitHeight: 40
border.color: control.pressed ? "#17a81a" : "#21be2b"
border.width: control.visualFocus ? 2 : 1
radius: 2
}
popup: Popup {
y: control.height - 1
width: control.width
implicitHeight: contentItem.implicitHeight
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
border.color: "#21be2b"
radius: 2
}
}
}