Results 1 to 4 of 4

Thread: Delegate y property change

  1. #1
    Join Date
    Feb 2014
    Location
    Paris
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Delegate y property change

    Hi there,

    I have a rectangle on which I want to put some elements positioned along x and y. To do this, I used a model in C++ and a ListView in QML. The delegate has a bind on x and y properties referring to a data of the model through a C++ conversion function. This works fine on x property but not on y property.

    I put a trace into onXchanged and onYchanged. X contains the correct value. Y gets the correct value then there's a second trace (this does not happen on x) indicating that y is 0 while the conversion function is called only once.

    Any idea?

    Thanks

    Qt4.8.5, QtQuick 1.1

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Delegate y property change

    You should give more information (code!). Is the rectangle inside any Layout?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Delegate y property change

    It might be easier to use a Repeater. Here is a working example that uses an array as a model (but you can replace it with a C++ model).

    javascript Code:
    1. Item {
    2. id: root
    3. width: 1000; height: 600
    4. property var model: [
    5. {"x": 100, "y": 50, "color": "red"},
    6. {"x": 60, "y": 320, "color": "blue"},
    7. {"x": 360, "y": 210, "color": "green"}
    8. ]
    9. Rectangle {
    10. color: "gray"
    11. width: 600
    12. height: 400
    13. anchors.centerIn: parent
    14.  
    15. border.color: Qt.darker(color)
    16. border.width: 1
    17.  
    18. Repeater {
    19. model: root.model
    20.  
    21. Item {
    22. x: modelData.x
    23. y: modelData.y
    24. Rectangle {
    25. width: 40; height: width; radius: width/2
    26. color: modelData.color
    27. anchors.centerIn: parent
    28. border.color: Qt.darker(color)
    29. border.width: 1
    30. }
    31. }
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 
    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.


  4. #4
    Join Date
    Feb 2014
    Location
    Paris
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Delegate y property change

    Thanks for your replies,

    My project has been postponed, I keep in mind your solution and try it as soon as I can.

    Many thanks

Similar Threads

  1. Access a property of delegate in listview
    By beemaneni in forum Qt Quick
    Replies: 1
    Last Post: 29th September 2016, 16:04
  2. Access delegate Property
    By beemaneni in forum Qt Quick
    Replies: 3
    Last Post: 10th February 2016, 19:08
  3. Increment a property inside repeater delegate
    By beemaneni in forum Qt Quick
    Replies: 3
    Last Post: 8th May 2015, 07:32
  4. change each separator's property
    By cic in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2013, 09:24
  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.