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
Popupis customised via aListViewcontent item but the delegate for the list view is defined as thedelegateproperty of theComboBox. Given that the content item of thePopupis 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
delegateModelhere is an instance of aDelegateModelthat is constructed by theComboBoximplementation.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
delegateModelproperty 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.
-
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.