Results 1 to 4 of 4

Thread: Access delegate Property

Hybrid View

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

    Default Re: Access delegate Property

    Hi
    i want to change the delegate property on button click.Here is my example:

    Qt Code:
    1. Window {
    2. visible: true
    3. width: 360
    4. height: 360
    5.  
    6.  
    7. Button{
    8. id: btn
    9. anchors{right: parent.right;rightMargin: 50;top: parent.top;topMargin: 150}
    10. width: 100
    11. height: 50
    12. text: "CLICK"
    13. MouseArea{
    14. anchors.fill: parent
    15. onClicked: {
    16. for(var j=0;j<3;j++)
    17. {
    18. listView.fruit_color[j] = "black" //Here i want to change the color of the text for all the 3 instances i have.If fruit colour is not an array it works fine.
    19. }
    20. }
    21. }
    22. }
    23.  
    24. Rectangle {
    25. width: 200; height: 200
    26.  
    27. ListModel {
    28. id: fruitModel
    29. property string language: "en"
    30. ListElement {
    31. name: "Apple"
    32. cost: 2.45
    33. }
    34. ListElement {
    35. name: "Orange"
    36. cost: 3.25
    37. }
    38. ListElement {
    39. name: "Banana"
    40. cost: 1.95
    41. }
    42. }
    43.  
    44.  
    45. Component {
    46. id: fruitDelegate
    47. Row {
    48. id: fruit
    49. Text { text: " Fruit: " + name; color: fruit.ListView.view.fruit_color[index] }
    50. Text { text: " Cost: $" + cost }
    51. Text { text: " Language: " + fruit.ListView.view.model.language }
    52. }
    53. }
    54.  
    55. ListView {
    56. id: listView
    57. property var fruit_color: ["green","red","blue"]
    58. model: fruitModel
    59. delegate: fruitDelegate
    60. anchors.fill: parent
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 10th February 2016 at 18:59. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Access delegate Property

    So additional to modifying the delegate as I've already pointed out you can

    - Modify a copy of the array then assign to the property.
    - Put the color into the model then modify the model.
    - Or if the color is an override, have an override property and use it in a property binding for the Text's color so it takes precendece over the usual color

    Oh, and use [code][/code] tags around code

    Cheers,
    _

    P.S.: why a mouse area inside the button, doesn't the button already have a clicked signal?

Similar Threads

  1. Increment a property inside repeater delegate
    By beemaneni in forum Qt Quick
    Replies: 3
    Last Post: 8th May 2015, 07:32
  2. how to access QAxObject property?
    By 0BLACK0 in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2015, 11:53
  3. Access parent property from repeater
    By c1223 in forum Qt Quick
    Replies: 3
    Last Post: 28th November 2014, 06:11
  4. Access object property in JS
    By folibis in forum Qt Quick
    Replies: 1
    Last Post: 18th January 2014, 13:23
  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.