Results 1 to 3 of 3

Thread: How to access child properties from another child in QML

  1. #1
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question How to access child properties from another child in QML

    I want to change image(child of Rectangle) on mouse hover of MouseArea(child of Rectangle)
    here is my code:
    javascript Code:
    1. Rectangle
    2. {
    3. width: 600; height: 400
    4. Row
    5. {
    6. id: myRow; spacing: 5; x: 50; y: 200
    7. Repeater
    8. {
    9. id: myRepeater; model: 10
    10. Rectangle
    11. {
    12. width: 100; height: 100;
    13. property int myIndex: index
    14. Image
    15. {
    16. source: "../GrayPoint.png"
    17. }
    18. MouseArea
    19. {
    20. id: mouseArea; anchors.fill: parent; hoverEnabled: true
    21. onEntered:
    22. updateUI( parent )
    23. }
    24. }
    25.  
    26. }
    27. }
    28. function updateUI( theParent )
    29. {
    30. theParent.childAt( 0, 0 ).source = "../RedPoint.png"
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 13th June 2013 at 11:44.

  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: How to access child properties from another child in QML

    Add a property to the parent and use it in both children.

    Cheers,
    _

  3. #3
    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: How to access child properties from another child in QML

    Or refer to the item using its id:

    javascript Code:
    1. Image {
    2. source: ma.containsMouse ? "../RedPoint.png" : "../GrayPoint.png"
    3. }
    4. MouseArea {
    5. id: ma
    6. hoverEnabled: true
    7. anchors.fill: parent
    8. }
    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.


Similar Threads

  1. Handle child of QProcess's child.
    By gcubar in forum Newbie
    Replies: 4
    Last Post: 30th November 2012, 02:59
  2. Access parent's function from child widget
    By el33t in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2011, 14:20
  3. Replies: 4
    Last Post: 17th January 2011, 14:05
  4. How To Access To Child's Of A Tab
    By hotjava in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2008, 13:21
  5. How to access myApp->method from a child
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2008, 13:22

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.