Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

align items vertically in rowlayout

Tags:

qt

qt5

qt-quick

qml

I am creating a row of buttons with qml using a Rowlayout but am having trouble aligning the buttons. I would like to have then aligned centrally along both vertical and horizontal directions.

I tried something as follows:

RowLayout
{
    anchors.fill: parent
    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

    ToolButton {
        //anchors.verticalCenter: parent.verticalCenter
        //anchors.horizontalCenter: parent.horizontalCenter
        Image {
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            source: "../images/search.png"
        }
    }

    ToolButton {
        //anchors.verticalCenter: parent.verticalCenter
        //anchors.horizontalCenter: parent.horizontalCenter
        Image {
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            source: "../images/search.png"
        }
    }
}

This results in something as the following image:

enter image description here

How can I make the images get aligned from the center out?

like image 524
Luca Avatar asked Oct 24 '25 04:10

Luca


1 Answers

You mean like this:

image

Add Layout.alignment: Qt.AlignRight | Qt.AlignVCenter to ToolButtons

RowLayout
{
    anchors.fill: parent
    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

    ToolButton {
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
        //anchors.verticalCenter: parent.verticalCenter
        //anchors.horizontalCenter: parent.horizontalCenter
        Image {
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            source: "search.png"
        }
    }

    ToolButton {
        Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
        //anchors.verticalCenter: parent.verticalCenter
        //anchors.horizontalCenter: parent.horizontalCenter
        Image {
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            source: "search.png"
        }
    }
}
like image 145
Farhad Avatar answered Oct 26 '25 02:10

Farhad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!