我有一个主 qml 文件,其中包含顶部项目是一个矩形,中间项目是加载不同 qml 文件的加载器,底部项目是一些文本。
根据我希望底部项目应该调整的加载器项目,我尝试使用锚点,但有些它不起作用,有人可以解释我如何做到这一点。
这是我的代码:
main.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle{
anchors.fill: parent
Rectangle{
id: toprect
width: 100
height: 100
color: "green"
anchors.horizontalCenter: parent.horizontalCenter
}
Loader{
id: middlerect
anchors.top: toprect.bottom
source: "qrc:/new.qml"
}
Rectangle{
id: belowrect
anchors.top: middlerect.bottom
Text{
text: "Bottom"
}
}
}
}
新的.qml
import QtQuick 2.0
import QtQuick.Controls 1.2
Item {
id: newid
Column{
spacing: 10
Rectangle{
width: 100
height: 50
color: "lightblue"
}
Rectangle{
width: 100
height: 50
color: "lightgreen"
}
}
}
问题:
底部项目与中间项目重叠