Customising ComboBox (delegateModel)
-
I implemented a customised combo box some time ago when I knew very little about QML (I don't know very much now!). I based it on following Qt examples and and other information I found online and didn't necessarily get all of the details.
Looking at it again recently, something initially confused me. The
Popup
is customised via aListView
content item but the delegate for the list view is defined as thedelegate
property of theComboBox
. Given that the content item of thePopup
is somewhat arbitrary, how does it know to use the delegate from the containingPopup
?The answer appears to be in the Qt example code which I based mine on:
contentItem: ListView { clip: true implicitHeight: contentHeight model: control.popup.visible ? control.delegateModel : null ...
Presumably
delegateModel
here is an instance of aDelegateModel
that is constructed by theComboBox
implementation.Is my understanding correct? I thought it worth asking this question as it does seem to be somewhat glossed over by the Qt documentation (is the
delegateModel
property explained anywhere?) and perhaps it might help someone else in future who is searching for an explanation. -
Yes this is correct. DelegateModel is a special beast containing both the model and the delegates created from it.
When you assign it to the model of a view you don't have to assign a delegate to the view.