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. ComboBox model avalable inside delegate but not in contentItem

ComboBox model avalable inside delegate but not in contentItem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 334 Views 1 Watching
  • 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    Hi,
    Can please someone tell me how i should reference the text of current index in the contentItem ?

      ComboBox {
                id: control
                model: ListModel {
                    id: cbItems
                    ListElement { tx: "Fr"; flg: "img/flagFr.png" }
                    ListElement { tx: "En"; flg: "img/flagBri.png" }           
                }  
                // displayText: tx  // ReferenceError tx
    
                delegate: ItemDelegate {
                     property alias curr:lab // tryed with alias
                    width: control.width
                    contentItem:Rectangle{
                        anchors.fill: parent
                        Row{
                            anchors.fill: parent
                        Image {
                            id: flag
                            source: flg
                            }
                        Text {
                            id:lab
                            text:tx
                            }
                    }
                    }
                    highlighted: control.highlightedIndex == index
                }
    
                indicator: Canvas {...}
    
                contentItem: Text {
                    text: /* show the selected index text*/
                    font: control.font
                    color: "black"
               }
    
                background: Rectangle { }
    
                popup: Popup {          
                    contentItem: ListView {}
                }
            }
    
    1 Reply Last reply
    0
    • Shrinidhi UpadhyayaS Offline
      Shrinidhi UpadhyayaS Offline
      Shrinidhi Upadhyaya
      wrote on last edited by
      #2

      Hi @LeLev , have you tried with this:-

      control.model.get(control.currentIndex).tx
      

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      ODБOïO 1 Reply Last reply
      5
      • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

        Hi @LeLev , have you tried with this:-

        control.model.get(control.currentIndex).tx
        
        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @Shrinidhi-Upadhyaya thank you very much it worked

        1 Reply Last reply
        3

        • Login

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