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 textRole doesn't work on custom delegate

ComboBox textRole doesn't work on custom delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 408 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.
  • A Offline
    A Offline
    Antonio Ortiz
    wrote on last edited by Antonio Ortiz
    #1

    Hi guys, I create a custom ComboBox component, when I use a simple model with a single role the component works with no problems, but if I use it with QAbstractListModel and set the roleText property I get this error:

    Unable to assign [undefined] to QString
    

    This is how I set the ComboBox:

    IndigoComboBox{
         model: mymodel
         textRole: "customUserRole"
    }
    

    This is the Text component inside the delegate:

    Text{
         text: modelData //I also try with textRole
    }
    

    Does anyone have an idea of what could be happening?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      It's the delegate that does the logic of fetching the data based on the textRole.

      change your delegate's text to :
      text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData

      where control is an id to your ComboBox

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Antonio Ortiz
        wrote on last edited by
        #3

        Thanks! that works perfectly

        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