2017-10-21 220 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

相关问题