Results 1 to 2 of 2

Thread: Access a property of delegate in listview

  1. #1
    Join Date
    Jul 2013
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Access a property of delegate in listview

    Hi,
    This is pretty simple but i lost somewhere when i am working on this .Here i post my example.
    I need to read a property which is declared inside a delegate from its parent.How do i do ?

    Qt Code:
    1. ListView{
    2. id: listView
    3. property bool indeeee: listView.contentItem.childrenRect.check
    4. state: listView.indeeee ? "moved" : ""
    5. delegate: delegateItem
    6. }
    7. Component{
    8. id: delegateItem
    9. Row{
    10. id: rowww
    11. spacing: 20
    12. property bool [COLOR="#FF0000"]check[/COLOR]:index===2 ? true : false
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    I tried to read with listView.contentItem.childrenRect.check which says unable to assign undefined to bool

    Regards
    Bala B

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access a property of delegate in listview

    You have to remember the delegate is a component so you don't have one delegate per view but rather one delegate per visible item. To access an item from a view you have ListView.currentItem, ListView.highlightItem or ListView.itemAt.

    So for example to know whether the current item is checked, you'd do:

    javascript Code:
    1. property bool indeeee: currentItem.check
    To copy to clipboard, switch view to plain text mode 

    However often you want to provide a relation in the other direction:

    javascript Code:
    1. ListView {
    2. property int checkedIndex: -1
    3.  
    4. delegate: MouseArea {
    5. // ...
    6. onClicked: ListView.view.checkedIndex = index // upon clicking I become the checked index in the view
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Just remember that only the delegate root (and not its children) has the "ListView" attached property and the "index" property available.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 16th May 2016, 23:50
  2. Access delegate Property
    By beemaneni in forum Qt Quick
    Replies: 3
    Last Post: 10th February 2016, 19:08
  3. Display decoration in listview delegate
    By manuelschneid3r in forum Qt Quick
    Replies: 1
    Last Post: 4th January 2016, 13:40
  4. Replies: 0
    Last Post: 31st January 2014, 15:50
  5. Replies: 1
    Last Post: 23rd June 2012, 13:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.