2012-05-20 45 views
3

我不知道是否有可能創建QML元素從而徹底和均勻地填充網格/父的寬度和高度的網格:子元素是否可以均勻填充網格?

Grid { 
    columns: 2 
    Repeater { 
     model: 4 
     Rectangle { 
      width: /* ??? */ 
      height:/* ??? */ 
     } 
    } 
} 

我認爲必須在此設置的絕對值。使用anchors.fill: parent將不起作用,以及諸如width: parent.width/2之類的東西。

回答

5

我想你忘了設置父母的(Grid元素)錨。你也可以通過它的id來引用一個元素。

Grid { 
    anchors.fill: parent 
    columns: 2 
    rows: 3 
    Repeater { 
     model: 6 
     Rectangle { 
      width: parent.width/parent.columns 
      height: parent.height/parent.rows 
     } 
    } 
}