1
为什么当我加载组件Loader
时,width
和height
不会从父项目复制?为什么不加载程序设置父母的宽度和高度?
此代码应显示一个红色的长方形,但它并不:
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
Pane {
width: 400
height: 300
Item {
anchors.fill: parent
Loader {
sourceComponent: redsq
}
}
Component {
id: redsq
Rectangle {
//width: 100;
//height: 40;
anchors.fill: parent
color: "red"
}
}
}
现在,如果我去掉了width
和height
和评论的anchors
一部分,它将很好地工作:
Rectangle {
width: 100;
height: 40;
//anchors.fill: parent
color: "red"
}
bin/qmlscene
的输出:
那么,这里有什么问题,是不是应该通过property binding
系统来传播属性?还是Loader
错过了某些功能?
_默认情况下,加载器并未被内容填充,也不是默认情况下内容的大小。这并非完全正确:[loader size behavior](http://doc.qt.io/qt-5 /qml-qtquick-loader.html#loader-sizing-behavior)。对于锚点工作,他们必须在装载机上。 – GrecKo