[Qt-qml] Layout question

Stephen Kelly steveire at gmail.com
Tue Sep 20 10:32:35 CEST 2011


Bo Thorsen wrote:

> Den 20-09-2011 09:51, Pris Matic skrev:
>> I think what Bo meant was that you can wrap each button by an Item
>> component:
> 
> No, I actually meant the exact opposite way :)
> 
> Item {
>    anchors.centerIn: parent
> 
>    Column {
>      Button {
>      ...
>    }
> }
> 
> This is a generic pattern in QML. When you want to center something, put
> an item around it and place that item in the center of the parent.
> 
> The item will resize to the contents automatically, so you don't need
> any anchors on the item, column or buttons.

That's not enough. You also need 

    width : childrenRect.width
    height : childrenRect.height

in the wrapping item. Otherwise it has 0 size and all you're doing is 
centering the top left point.



More information about the Qt-qml mailing list