Why anchors.centerIn doesn't working for Colum

2019-04-11 12:14发布

I have this piece of QML code:

 Column {
     spacing: units.gu(2)
     anchors {
         fill: parent
         centerIn: parent
     }
     Row {
         spacing: units.gu(4)
         ...
     }
     Row {
         spacing: units.gu(4)
         ...
     }
     Row {
         spacing: units.gu(4)
         ...
     }
     Row {
         spacing: units.gu(4)
         ...
     }
 }

I'm trying to center Column in its parent element (a Page element), but it doesn't work. If a try to centerIn: parent in one of the Rows, it works, but as I have 4 Rows, it break the layout. But Rows respond to this, instead my Column.

Why make centerIn: parent works for Column? Theres another ways to center this?

标签: qt qml
1条回答
对你真心纯属浪费
2楼-- · 2019-04-11 12:48

you can't set 'fill' and 'centerIn', so put column in anchors.centerIn:parent and the Rows in anchors.horizontalCenter:parent.horizontalCenter (centerIn is not allowed cause it conflicts the parent vertical positionning....).

查看更多
登录 后发表回答