Results 1 to 4 of 4

Thread: Access parent property from repeater

  1. #1
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Access parent property from repeater

    Not entirely sure how to do this but:

    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Window 2.0
    4. import QtQuick.Controls.Styles 1.2
    5.  
    6.  
    7. ApplicationWindow {
    8. id: theGui
    9. property int appHeight: theGui.height
    10. objectName: "mainWindow"
    11. visible: true
    12. visibility: "Maximized"
    13. title: qsTr("Map")
    14.  
    15. Repeater {
    16. id: mapRepeater
    17. model: mapModel
    18. Rectangle { width: xSize * model.modelData.scale; height: ySize * model.modelData.scale
    19. color: ((xIndex % 2 == 1 && yIndex % 2 == 0) || (xIndex % 2 == 0 && yIndex % 2 == 1)) && (xIndex < 90) ? "white" : "black"
    20. x: xPos * model.modelData.scale
    21. y: yPos * model.modelData.scale
    22. Text { text: (yIndex == 10 || xIndex == 14) ? "" : "(" + xIndex + ", " + yIndex + ")"
    23. anchors.right: parent.right
    24. anchors.top: parent.top
    25. font.pointSize: 25 * model.modelData.scale
    26. color: (xIndex % 2 == 1 && yIndex % 2 == 0) || (xIndex % 2 == 0 && yIndex % 2 == 1) ? "black" : "white"
    27. }
    28. }
    29. }
    30.  
    31.  
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    From the rectangle component of the Repeater how would I access the "ApplicationWindow" height (i.e. appHeight). I tried with global variables (Qt.appHeight) but couldn't get that to work.

    Essentially I want the rectangle to be able to access the dimensions of the ApplicationWindow.

    Thanks

  2. #2
    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: Access parent property from repeater

    theGui.height
    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.


  3. #3
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Access parent property from repeater

    It returns "0". But the window is clearly larger than that.

  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 parent property from repeater

    Have you tried with only one child of ApplicationWindow?

    Say and Item that fills the window and having the Repeater inside it?

    The way the ApplicationWindow is layouted it is designed for only one content item, but your repeater currently adds several.

    Cheers,
    _

Similar Threads

  1. Access object property in JS
    By folibis in forum Qt Quick
    Replies: 1
    Last Post: 18th January 2014, 14:23
  2. Styling a Sub-Control based on a Property of the Parent
    By TheGrimace in forum Qt Programming
    Replies: 0
    Last Post: 10th September 2013, 16:32
  3. How to access to methods of parent class
    By tonnot in forum General Programming
    Replies: 3
    Last Post: 29th June 2011, 08:04
  4. Replies: 2
    Last Post: 27th May 2010, 02:55
  5. QPainter and how to access the parent variables.
    By Teuniz in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2007, 15:06

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.