Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 a ListView content item but the delegate for the list view is defined as the delegate property of the ComboBox. Given that the content item of the Popup is somewhat arbitrary, how does it know to use the delegate from the containing Popup?

    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 a DelegateModel that is constructed by the ComboBox 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.


  • Qt Champions 2018

    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.


  • Qt Champions 2018

    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.



  • @GrecKo Thanks for confirming.


Log in to reply