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. How to access ListView property inside delegate
Forum Updated to NodeBB v4.3 + New Features

How to access ListView property inside delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.0k 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.
  • M Offline
    M Offline
    Madhu M S
    wrote on last edited by p3c0
    #1

    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
    }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      8
      • M Offline
        M Offline
        Madhu M S
        wrote on last edited by
        #3

        Hi Sir,

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

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

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

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          6

          • Login

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