Important: Please read the Qt Code of Conduct -

[SOLVED] Qml Combobox delegate?

  • Hey guys,

    I'm wondering if it is possible to use a list of custom classes as model for a qml combobox? I don't see any option to assign a delegate.

    What I want:

    • I have list of configurations (class config).
    • Each config has a name and a bunch of properties.
    • I want to fill a combobox with all available configs (model: QList<config*>).
    • If I select an item from the combobox I want to display some components to edit properties of the selected item.

    Any suggestions how I should implement it?


  • Moderators

    @themts AFAIK you can use all derivatives of QAbstractItemModel like QAbstractListModel or QStringListModel and also object list models using QList<QObject*>.
    Have a look at these examples. IMO, they should work with ComboBox too.

  • I know these samples and I already used models with ListViews but Listview has a delegate.
    Let's say I use a QList<QObject*> as model. Which property of my QObject will be used as text in the comboBox?

  • Moderators

    @themts So assuming your QObject subclassed class has a property say for eg. name then to populate ComboBox with it you will have to set textRole to 'name'

    ComboBox {
        model: myModel
        textRole: 'name'

  • Ahhhhh! Thanks!
    I didn't know what textrole is for!


Log in to reply