一番上のアイテムが長方形で、真ん中のアイテムがさまざまな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"
}
}
}
}
new.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"
}
}
}
問題:
一番下のアイテムが真ん中のアイテムに重なっています