Reputation: 145
I have a QML ComboBox whose model is defined as a C++ QList < QObject* >. When I open the drop down list, I can see all items defined in the C++ model, but after selection, the selected item is not shown. So, items are only visible in the drop down element. The relevant part of the qml file is:
ComboBox {
id: placesCombo
anchors.top: parent.top
width: parent.width
model: myModel
delegate: ItemDelegate {
width: placesCombo.width
contentItem: Text {
id: placesComboItem
text: displayLabel
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
}
}
How to display in the closed combobox the item text previously selected in the drop down element?
Upvotes: 4
Views: 3195
Reputation: 244291
According to the docs:
textRole : string
This property holds the model role used for populating the combo box.
When the model has multiple roles, textRole can be set to determine which role should be displayed.
You have to indicate the role of the model to be displayed through textRole.
ComboBox {
id: placesCombo
textRole: "displayLabel"
...
}
Upvotes: 6