Hi,
I have a GridView
GridItemView
{
id: grid
width: 500
height: 200
cellWidth: 200
cellHeight: 80
anchors.verticalCenter: parent.verticalCenter;
anchors.horizontalCenter: parent.horizontalCenter;
model: myModel
delegate: MyDelegate{}
}
GridItemView
{
id: grid
width: 500
height: 200
cellWidth: 200
cellHeight: 80
anchors.verticalCenter: parent.verticalCenter;
anchors.horizontalCenter: parent.horizontalCenter;
model: myModel
delegate: MyDelegate{}
}
To copy to clipboard, switch view to plain text mode
and MyDelegate is a simple rectagle with parent size:
Rectangle
{
property int margin: 20;
width: GridView.view.cellWidth - margin
height: GridView.view.cellHeight - margin
Text
{
id: textValue
text: modelVal
horizontalAlignment: Text.AlignVCenter
font.pixelSize: 30
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
}
Rectangle
{
property int margin: 20;
width: GridView.view.cellWidth - margin
height: GridView.view.cellHeight - margin
Text
{
id: textValue
text: modelVal
horizontalAlignment: Text.AlignVCenter
font.pixelSize: 30
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
}
To copy to clipboard, switch view to plain text mode
The delegates have correct size but elements is aligned on the top-left of the cell grid.
I've tried to add
anchors.centerIn: parent.Center
anchors.centerIn: parent.Center
To copy to clipboard, switch view to plain text mode
in MyDelegate but don't works:all elements is placed at the center of GridView.
I've tried also to add margins but don't works.
How I can center the delegate element into the cell?
Bookmarks