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. Delegating item for combobox (QML)
Qt 6.11 is out! See what's new in the release blog

Delegating item for combobox (QML)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 2.9k 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.
  • P Offline
    P Offline
    Praveen kk
    wrote on last edited by
    #1

    Hi, My requirement is like, i have following model data for combobox
    suppose > model: ["102", "304", "509"]
    i need to display these model data in combobox as below.

    Combodata
    Code-1
    Code-2
    Code-3

    and if i selected Code-2 i should get 304 as value (actual model data.). How
    can i do this in QML combobox. ? Is there any way to achieve this in cobobox
    as we can do in tableview with delegate. ? Could you please help me to sove
    thi.?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      literA2
      wrote on last edited by
      #2

      You try to do this:

      ComboBox {
        id: cmb
        property string currentValue: ""
        currentIndex: 0
        model: ListModel {
          id: cbItems
          ListElement { text: "Code-1"; value: "102" }
          ListElement { text: "Code-2"; value: "304" }
          ListElement { text: "Code-3"; value: "509" }
        }
        width: 200
        onCurrentIndexChanged: {
          cmb.currentValue = cbItems.get(currentIndex).value;
        }
      }
      

      Hope this helps!

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Praveen kk
        wrote on last edited by
        #3

        Got some easy fix by creating Wrapper for model.

        code below*****

        // creating wrapper for the model
        Repeater {
        model: tableModels.Study.GetStudyIDList(tableModels.Patient.get(modelIndx, "ID")) // My actual model exposed from C++ side
        delegate: Item {
        Component.onCompleted: {
        wrapper.append({text: "Code " + getStudyID(index), value: modelData })
        }
        }
        }
        ComboBox {
        id: studyList
        height: 30
        model: ListModel { id: wrapper }
        }

         function getStudyID( index )
         {  // just append 0 befor number from 0 -9
            var studyNum = index + 1;
            if(index<10 && index>-1)
            {
               studyNum = "0" + studyNum;
            }
            return studyNum;
        }
        

        Anyway thank you literA2 ..!

        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