I am facing trouble in aligning group boxes to horizontally centered along with scrollview in Qml.
I have tried anchors.horizontalCentre: Qt.AlignHCenter and Layout.alignment: Qt.AlignHCenter. But none of them works. Please find below sample code which aligns horizontally left.
ApplicationWindow {
id: root
width: 500
height: 100
visible: true
ScrollView {
anchors.fill: parent
clip: true
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
ColumnLayout { //Arrange GroupBox's in column wise
anchors.fill: parent
spacing: 10
anchors.margins: 10
Layout.alignment: Qt.AlignHCenter
GroupBox {
title: qsTr("Sample1")
ColumnLayout { //Arrange child Items in column wise
Text { id: gr1text1; text: qsTr("Group 1, Text 1") }
Text { id: gr1text2; text: qsTr("Group 1, Text 2") }
}
}
GroupBox {
title: qsTr("Sample2")
ColumnLayout { //Arrange child Items in column wise
Text { id: gr2text1; text: qsTr("Group 2, Text 1") }
Text { id: gr2text2; text: qsTr("Group 2, Text 2") }
}
}
}
}
}
The output of the above code is captured below

I did a couple of changes:
ScrollViewwithFlickableFlickableto take the width from the children, but, the height from the parent item. We do this, because you indicated the need for a verticalScrollBarso the height cannot be taken from the childrenFlickableto have the anchors for horizontal alignmentScrollBar.verticaltoFlickableand set the width to20pixels for a fat scrollbarcontentWidthandcontentHeightto the parentColumnLayout. Doing this helps theScrollBarwork out the geometry of the content versus the geometry of theFlickableYou can Try it Online!
Also, consider using
ListViewsince it has a natural ability to apply aScrollBar. The following example demonstrates how your example can be expressed using aListViewwith amodel:You can Try it Online!