qtqml

Why anchors.centerIn doesn't working for Column elements?


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?


Solution

  • 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....).