Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Delegating item for combobox (QML)

    QML and Qt Quick
    2
    3
    2063
    Loading More Posts
    • 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
      Praveen kk last edited by

      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 Reply Quote 0
      • L
        literA2 last edited by

        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 Reply Quote 0
        • P
          Praveen kk last edited by

          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 Reply Quote 0
          • First post
            Last post