2017-10-21 223 views
0

我現在被卡住了這個QML項目。這是一個簡單的2x3網格,它似乎粘在屏幕的左側。如果我應用anchors.centerIn: parent,它會使GridView居中但忽略我的TopMargin屬性。如果我能得到任何援助,這將不勝感激。我知道我可以申請leftMargin:對它來說,但它有點難看。我怎樣才能讓這個GridView出現在我窗口的中心?

GridView { 

    id: gridView 
    interactive: false 
    clip: true 

    // anchors.centerIn: parent 
    anchors.left: parent.left 
    anchors.top: titleBarContainer.bottom 
    anchors.topMargin: 20 
    anchors.right: parent.right 

    width: 400 
    height: parent.height 

    currentIndex: -1 

    cellWidth: 200 
    cellHeight: 200 

回答

0
... 

anchors.top: titleBarContainer.bottom 
anchors.topMargin: 20 
anchors.horizontalCenter: parent.horizontalCenter 

width: 400 
height: parent.height 

... 
+0

看起來是做了..想我是愚蠢的。謝謝! – Cain

+0

雖然我應該注意..如果我使用parent.width而不是'400'作爲寬度值,它會繼續向左移動。你知道爲什麼嗎? – Cain

+0

這將使GridView覆蓋父級的整個寬度,這使得水平中心錨定變得毫無意義。 GridView內部發生的事情是它從左上角開始列出它的項目。 – jpnurmi