在Qt中将某行水平居中

时间:2019-04-15 11:29:15

标签: qt qml

我是QML的新手,我想在Row(或RowLayout)中放置一个(也只有一个)商品中心。如下面的代码所示,我希望将“ Hello”放置在窗口的中心(一行)。

    Row {
        id : titleRow
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.bottom

        topPadding: 50
        bottomPadding: 50

        Text {
            text: "Hello"
            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
        }
    }

我使用Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter,但显然无法正常工作。我也尝试了anchors.centerIn: parent,但也失败了。

任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:1)

Row不是布局。这是Positioner。因此,您不能将Layout.*属性与其一起使用。

改为使用RowLayout