QML anchors to ApplicationWindow via id not work

后端 未结 2 1411
走了就别回头了
走了就别回头了 2021-01-18 03:26

I test a simple QML(Qt sdk version 5.3.2) program like this

import QtQuick 2.3
import QtQuick.Controls 1.2

ApplicationWindow {
    visible: true
    width:          


        
2条回答
  •  生来不讨喜
    2021-01-18 03:54

    ApplicationWindow does not ultimately derive from Item, so it does not have an anchors property that's why using the window's id does not work. So why does using parent? Because the children you define in an ApplicationWindow become children of an intermediate Item called contentItem:

    If you assign an Item to the data list, it becomes a child of the Window's contentItem, so that it appears inside the window. The item's parent will be the window's contentItem, which is the root of the Item ownership tree within that Window. ... It should not generally be necessary to refer to the data property, as it is the default property for Window and thus all child items are automatically assigned to this property.

提交回复
热议问题