2016-12-26 138 views
0

有什麼辦法去除QML佈局的構成要素的開始和結束的利潤率?QtQuick佈局利潤率

這裏是ColumnLayout與幾個孩子的例子。現在的問題是如何消除這些頂部和底部邊緣,並重新分配所有的孩子一起父佈局的最大高度。

Margins

ColumnLayout { 
    id: dotColumn 
    anchors.horizontalCenter: bg.horizontalCenter 
    height: root.height 
    Repeater { 
     id: repeater 
     model: root.model 

     Item { 
      id: activeDot_container 

      property int radius: 15 
      width: radius * 2 
      height: radius * 2 

      Rectangle { 
       anchors.centerIn: parent 
       radius: parent.radius 

       width: radius * 2 
       height: radius * 2 

       color: Palette.colors['deepPurple']['500'] 
      } 
     } 
    } 
} 
+0

好的,您必須至少向我們展示您的代碼,以便我們可以幫助您。 – folibis

+0

@folibis我的壞。代碼附加。 –

+0

您的代碼不完整,所以我只能假設如何解決這個問題。試着在'activeDot_container'項目 – folibis

回答

0

一對夫婦與佈局定位的實驗後,我特地用以下解決方案。

假設利潤我想消除有佈局的孩子之間的間距的一半大小,我們可以設置切緣陰性的開頭和佈局組件的結尾,拉伸它,直到第一個和最後一個孩子開始/結束對齊佈局。我用來計算利潤率

功能:

function getMargin() { 
    var height = root.height; 
    var spacing = (height - root.radius * 2 * model.length)/model.length; 
    return spacing/2; 
} 

哪裏root是面板組件的父,root.radius*2代表的佈局兒童項目的大小,可以用另一個子維度和model.length代表指望孩子來代替。

然後,我們可以只設置錨佈局組件,並設置相應的利潤。

ColumnLayout { 
    anchors.top: root.top 
    anchors.bottom: root.bottom 
    anchors.topMargin: -1 * getMargin() 
    anchors.bottomMargin: -1 * getMargin() 
    Repeater { 
     model: root.model 
     Item { 
      property int radius: root.radius 
      width: radius * 2 
      height: radius * 2 
      /* more code */ 
     } 
    } 
} 

P.S.相同的解決方案可通過用左/右替換佈局頂部/底部錨被應用到的RowLayout。

0

不能內部佈局對齊項目都頂部和上下。作爲一種變通方法,你可以把物品與可變y容器內,如下圖所示:

Window { 
    visible: true 
    visibility: Window.Maximized 

    ColumnLayout { 
     anchors.horizontalCenter: parent.horizontalCenter 
     height: parent.height 
     spacing:1 
     Repeater { 
      id: repeater 
      model: 10 
      Rectangle { 
       color: "green" 
       property int radius: 15 
       width: radius 
       Layout.fillHeight: true 
       Rectangle { 
        anchors.horizontalCenter: parent.horizontalCenter 
        y: index * (parent.height - height)/(repeater.count - 1) 
        radius: parent.radius 
        width: radius * 2 
        height: radius * 2 
        color: "blue" 
       } 
      } 
     } 
    } 
}