How to access ListView property inside delegate



  • I have two list views and using the same delegate to display the contents. I have defined the property inside list view. How do i access the properties defined in list view inside delegate.

    I want to set the color property of delegate from the property defined in ListView

    Component{ 
            id:listcomp
            Text{text:name;font.pixelSize: 12;color:"white"}
        }
    
    ListView{
    
     property color col: "blue"
    delegate:listcomp
    }
    
    ListView{
    
     property color col: "red"
    delegate:listcomp
    }
    


  • ListView has property called contentItem. Delegate object will parented to contentItem. So you can use the following inside your delegate to set the property present inside your ListView.
    Try
    color :parent.parent.col



  • Hi Sir,

    I tried for this, it works fine. Thank you for your valuable solution.



  • Cool. That is nice. You can put the issue to SOLVED state.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.