QML : anchors.verticalCenter does not work

  • Hello everyone,
    I show you my code, It will be easier to explain my problem.

    Window {
        id : windowId
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello")
        color :"grey"
           id : myButton
           width : 100
           height : 100
           color : "green"
           anchors.verticalCenter: windowId.verticalCenter

    If I replace windowId by parent it works but I do not understand why ? It should work with id from my window

    Can you explain what is wrong.

    thanks a lot

  • Moderators

    because the Window is not an item actually. it has a contentItem (default property, which gets the child items reparented to). So use this property, or even better, simply use parent

Log in to reply