Results 1 to 4 of 4

Thread: Access delegate Property

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

    Default Access delegate Property

    Hi
    I want to access the delegates property when i click an button. Here is the simple code
    Qt Code:
    1. ListView{
    2. id: listt
    3. model: 10
    4. clip:true
    5. width: parent.width
    6. spacing: 25
    7. height: 500
    8. anchors{left: parent.left;leftMargin: 50;top: parent.top;topMargin: 50}
    9. delegate: listDelegate
    10. }
    11.  
    12. Component {
    13. id: listDelegate
    14.  
    15. Item{
    16. CheckBox{
    17. id: checker
    18. text: "A"
    19. checked:true
    20. }
    21. }
    22. }
    23.  
    24. Button{
    25. anchors{right: parent.right;rightMargin: 50;top: parent.top;topMargin: 150}
    26. width: 100
    27. height: 50
    28. text: "CLICK"
    29. MouseArea{
    30. anchors.fill: parent
    31. onClicked: {
    32. // Here i want to read or write all 10(model) values.
    33. }
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 
    How do i achieve delegates property when i click an button.How do i take reference for it and access outside for reading and writing?
    Please suggest the ways to do.


    Regards
    Bala Beemaneni
    Last edited by anda_skoa; 10th February 2016 at 10:33. 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

    You can use listt.itemAt() to access the delegate instance at any given index.

    However, there is likely a more declarative way for whatever you are trying to do.
    Can you explain what your goal is?

    Cheers,
    _

  3. #3
    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 19:59. Reason: missing [code] tags

  4. #4
    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, 08:32
  2. how to access QAxObject property?
    By 0BLACK0 in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2015, 12:53
  3. Access parent property from repeater
    By c1223 in forum Qt Quick
    Replies: 3
    Last Post: 28th November 2014, 07:11
  4. Access object property in JS
    By folibis in forum Qt Quick
    Replies: 1
    Last Post: 18th January 2014, 14:23
  5. Replies: 1
    Last Post: 23rd June 2012, 14: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.