Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Qml Combobox delegate?
QtWS25 Last Chance

[SOLVED] Qml Combobox delegate?

Scheduled Pinned Locked Moved QML and Qt Quick
qmlcombobox
5 Posts 2 Posters 7.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    themts
    wrote on last edited by themts
    #1

    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?

    Thanks!
    CU
    mts

    p3c0P 1 Reply Last reply
    0
    • T themts

      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?

      Thanks!
      CU
      mts

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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.

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        themts
        wrote on last edited by
        #3

        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?

        p3c0P 1 Reply Last reply
        0
        • T themts

          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?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @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'
          }
          

          157

          1 Reply Last reply
          1
          • T Offline
            T Offline
            themts
            wrote on last edited by
            #5

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

            THANKS
            cu
            mts

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved