Skip to content

Commit

Permalink
[Fix Bug] CusComboBox support ListModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jared2020 committed Nov 23, 2021
1 parent 435b3ac commit 5ba2c08
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions examples/TaoQuickShow/Contents/General/DataEntrys.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ Item {
width: 120
displayText: qsTr(currentText) + trans.transString
}
CusComboBox {
id: comboBox3
width: 120
height: 26
textRole: "name"
valueRole: "cost"
font.pixelSize: 10
model: holdersType
}

ListModel {
id: holdersType
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
}
Item {
width: 20
Expand Down
4 changes: 3 additions & 1 deletion src/TaoQuick/Qml/CusComboBox/CusComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ComboBox {
property color colorHovered: CusConfig.imageColor_hovered
property color colorPressed: CusConfig.imageColor_pressed
property color colorDisable: CusConfig.imageColor_disabled

CusImage {
id: baseImage
source: imgUrlNormal
Expand Down Expand Up @@ -111,7 +112,8 @@ ComboBox {
contentItem: CusLabel {
leftPadding: cusComboBox.leftPadding
rightPadding: cusComboBox.indicator.width + cusComboBox.spacing
text: qsTr(String(modelData)) + CusConfig.transString
property var dData : cusComboBox.textRole ? (Array.isArray(cusComboBox.model) ? modelData[cusComboBox.textRole] : model[cusComboBox.textRole]) : modelData
text: qsTr(String(dData)) + CusConfig.transString
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
Expand Down

0 comments on commit 5ba2c08

Please sign in to comment.