为什么anchors.centerIn不适用于Column元素?

ayr*_*ton 3 qt qml

我有这条QML代码:

 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)
         ...
     }
 }
Run Code Online (Sandbox Code Playgroud)

我试图将Column置于其父元素(Page元素)中,但它不起作用.如果尝试centerIn: parent在其中一行中,它可以工作,但由于我有4行,它会打破布局.但是Rows回应了这个,而不是我的专栏.

为什么要centerIn: parent为Column工作?还有另一种方法可以集中体现吗?

The*_*roo 9

你不能设置'fill'和'centerIn',所以把列放在anchors.centerIn:parent和Anchors.horizo​​ntalCenter中的行:parent.horizo​​ntalCenter(不允许centerIn导致它与父垂直定位冲突....) .

  • 我能看到一个如何做到这一点的例子吗? (2认同)