Window Qml issue of control can not use the id layout positioning

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Window controls Qml solve the problem can not be using id layout positioning.

To reproduce the problem

  • After running the Rectangle and not in accordance with the expected behavior at the bottom, but the same layout (top default layout).
Window {
    id: root
    visible: true
    width: 640
    height: 480

    Rectangle {
    	id: rect
        width: 100; height: 100
        anchors.bottom: root.bottom
        color: "red"
    }
}

analysis

  • First check the official Qt documentation look for clues, since it can not find the layout of anchorsthe document layout, document by global search found the following information.
Note: You can only anchor an item to siblings or a parent. 
注意:只能将项目锚定到同级或父级。 
  • It can be speculated Window of rootid points is not derived from the Item (or QQuickItem) of.
  • Print Window by the id and the parent property are QQuickWindowQmlImpl and QQuickRootItem, it certainly is QQuickWindowQmlImplnot inherited in QQuickItem, resulting in less than a layout problem.
  • I feel there is wrong, but also to find the next document, see the following information:
[default] data : list<Object>

The data property allows you to freely mix visual children, resources and other Windows in a Window.
If you assign another Window to the data list, the nested window will become "transient for" the outer Window.
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.
If you assign any other object type, it is added as a resource.
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.

data属性允许您在Window中自由混合可视子项,资源和其他Windows。
如果将另一个窗口分配给数据列表,嵌套窗口将变为"瞬态"外部窗口。
如果将一个Item分配给数据列表,它将成为Window的contentItem的子项,以便它出现在窗口内。 项目的父项将是窗口的contentItem,它是该窗口中项目所有权树的根。
如果指定任何其他对象类型,则将其添加为资源。
通常不需要引用data属性,因为它是Window的默认属性,因此所有子项都会自动分配给此属性。
  • Probably means Item Window is the root window is attached contentItemon.

Solution

  • Use parentor root.contentItemor Window.contentItemalternatively rootanchor as layout.

Guess you like

Origin blog.csdn.net/nicai_xiaoqinxi/article/details/91549280