Results 1 to 5 of 5

Thread: PropertyChanges on repeater elements

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default PropertyChanges on repeater elements

    Hi,

    I'm trying to change the source of the repeater elements with condition included however the condition wasn't included after the changes

    Qt Code:
    1. Row {
    2. id: level
    3. Repeater {
    4. id:levelRepeater
    5. model: 15
    6.  
    7. Image {
    8. id: levelImg
    9. source: levelArea.containsMouse ? "../images/mdpi/level-off-over-vertical.png" : "../images/mdpi/level-off-vertical.png"
    10. fillMode: Image.PreserveAspectFit
    11.  
    12. MouseArea {
    13. id: levelArea
    14. anchors.fill: parent
    15. hoverEnabled: true
    16. onClicked: {
    17. if (volume === -1 || index > volume) {
    18. volume = index
    19. for(var i = 0; i <= index; ++i) {
    20. level.children[i].source = levelArea.containsMouse ? "../images/mdpi/level-on-over-vertical.png" : "../images/mdpi/level-on-vertical.png"
    21. }
    22. } else if (index < volume) {
    23. for(var y = volume; y > index; --y) {
    24. level.children[y].source = levelArea.containsMouse ? "../images/mdpi/level-off-over-vertical.png" : "../images/mdpi/level-off-vertical.png"
    25. }
    26. volume = index
    27. }
    28. }
    29. }
    30. }
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    I also tried using states and PropertyChanges, however i am having problem assigning the target of the repeater items, any idea how?

    I can't find any related issue in the forum and on the net.
    Any help is greatly appreciated.

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

    Default Re: PropertyChanges on repeater elements

    Inside the mouse area's on clicked the condition "containsMouse" will always be true, because that is necessary to get the click.

    Did you want to create a new binding for source?

    The over all condition doesn't look that complicated, you could try to make the initial source binding already include the check for volume.

    It look like the filename has "over" in it when the mouse is hovering the image, right?
    And it has "on" when the volume is greater or equal the current index, otherwise "off"?

    Something like
    Qt Code:
    1. readonly property over = levelArea.containsMouse ? "over-" : ""
    2. readonly propery onOff = index <= volume = "on-" : "off-"
    3. source: "../images/mdpi/level-" + onOff + over + "vertical.png"
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PropertyChanges on repeater elements

    Thank you anda_skoa for the response, it is greatly appreciated

    However I resolved my issue by using states. This time I included the states in every repeater elements unlike before where i placed the states on row element.
    Then changed the state of every affected element in mousearea onclicked method.

    Cheers!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PropertyChanges on repeater elements

    Even with states it should be easier to change the state value with a binding instead of having to do imperative programming.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    joko (15th October 2014)

  6. #5
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PropertyChanges on repeater elements

    Thank you for your response I was able to implement the binding of source and eliminates several lines of code especially those states!
    Last edited by joko; 15th October 2014 at 12:25.

Similar Threads

  1. Replies: 3
    Last Post: 18th June 2013, 22:29
  2. Performance Issue When Using Repeater
    By alizadeh91 in forum Qt Quick
    Replies: 7
    Last Post: 24th July 2012, 14:04
  3. Replies: 0
    Last Post: 13th November 2011, 22:44
  4. Modify c++ model data from QML Repeater
    By laszlo.gosztola in forum Qt Quick
    Replies: 7
    Last Post: 19th October 2011, 14:35
  5. Repeater and itemAt undefined references
    By porterneon in forum Qt Quick
    Replies: 1
    Last Post: 21st September 2011, 15:32

Tags for this Thread

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.