我测试了这样一个简单的QML(Qt sdk版本5.3.2)程序
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
id: appWin
Text {
text: qsTr("Hello World")
anchors.bottom: parent.bottom
}
}
我希望文本将放在应用程序窗口的底部,这是有用的 . 但是,如果我将 anchors.bottom: parent.bottom
更改为 anchors.bottom: appWin.bottom
(通过id),锚点不再起作用,这是一个错误吗?
2 回答
ApplicationWindow
最终并非来自Item
,因此它没有's why using the window' sid
不起作用的anchors
属性 . 那么为什么要使用parent
?因为您在ApplicationWindow
中定义的子项名为children of an intermediateItem
,称为contentItem
:这看起来像一个bug,但它可以按照以下设计docs:
在锚定时我们如何指定
direct parent
并不是很清楚 . QML翻译者只能接受parent
来引用父qml项目 .