Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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
    }
    

  • Qt Champions 2017

    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.


  • Qt Champions 2017

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


Log in to reply