Allan Ruin
Allan Ruin

Reputation: 5277

Centering one item horizontally in a Row in Qt

I am new to QML, and I would like to position one (and only one) item center in a Row (or RowLayout). As the code shown below, I want the "Hello" to be place on center(of a row) of my window.

    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
        }
    }

I use Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter, but apparently it's not working. I also try anchors.centerIn: parent, which also failed.

Any help would be greatly appreciated, thank you !

Upvotes: 0

Views: 967

Answers (1)

Dimitry Ernot
Dimitry Ernot

Reputation: 6584

Row is not a layout. It's a Positioner. So, you cannot use Layout.* properties with it.

Use RowLayout instead.

Upvotes: 2

Related Questions