[SOLVED]A problem in ComboBox with image
-
Hi,
i would like to place icon to the dropdown list, so I made some codes like this:...... model: ListModel { id: cbItems ListElement { text: ""; iconSource: "image1"} ListElement { text: ""; iconSource: "image2"} } __dropDownStyle: MenuStyle { id: dropDownMenuStyle frame: dropDownMenuStyleFrame // __menuItemType: "comboboxitem" itemDelegate.label: Rectangle { width: root.width - 50 height: root.height color: "transparent" Image { id: operatorPic width: height height: operatorPictureHeight anchors { left: parent.left leftMargin: 2 verticalCenter: parent.verticalCenter } source: operatorPic.height === 0 ? "" : styleData.iconSource } ITextLabel { width: parent.width - operatorPic.width - 2 - 5 height: parent.height fontSize: 20 fontColor: styleData.selected ? "white" : "black" text: styleData.text wrapMode: Text.WrapAtWordBoundaryOrAnywhere horizontalAlignment: Text.AlignLeft anchors.left: operatorPic.right anchors.leftMargin: 5 } } itemDelegate.background: Rectangle { z: 1 opacity: 0.5 height: root.height color: styleData.selected ? "#0098DF" : "transparent" } }
I know
source: operatorPic.height === 0 ? "" : styleData.iconSource
does not work but I have no idea how to deal with it.Does anybody tell me how to do it?
Thanks. -
Hi @beidaochuan
You havestyleData.index
and access to the model. Combine it and usesource: cbItems.get(styleData.index).iconSource