Hello and Happy New Year,
I'm trying to create a simple grid in QML whose elements are rectangles that contains a image and a text. I want to create a mobile-like menu.
I've two files, one with a generic menu item and another with the grid of those items.
It works well if the height and width of the items are hardcoded but it doesen't if I try to adapt on the parent size (height: parent.height/3). All of the items appear on the center of the parent and the image is not show.

How can I achive it, so when the parent size changes the elements will adapt?

Code:
Qt Code:
  1. //mitem.qml
  2. import QtQuick 2.0
  3.  
  4. Rectangle {
  5. width: 50 // Doesn't work width: parent.width/3
  6. height: width
  7. Image{
  8. id:img
  9. width: parent.width*3/5
  10. height: width
  11. anchors.horizontalCenter: parent.horizontalCenter
  12. source: "http://qmlbook.org/_images/flow.png"
  13.  
  14. }
  15. Text{
  16. anchors.bottom: parent.bottom
  17. anchors.horizontalCenter: parent.horizontalCenter
  18. text: "Test"
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. //main.qml
  2. import QtQuick 2.0
  3.  
  4. Rectangle{
  5. id: root
  6. width: 160
  7. height: 160
  8. Grid {
  9. id: grid
  10. rows: 2
  11. columns: 2
  12. anchors.centerIn: parent
  13. spacing: 8
  14. mitem { }
  15. mitem { }
  16. mitem { }
  17. mitem { }
  18. }
  19.  
  20. }
To copy to clipboard, switch view to plain text mode 

Thanks!