Reputation: 664
I'm working on a python desktop app using QML.
I have this in my QML file:
SplitView {
anchors.fill: parent
orientation: Qt.Horizontal
Rectangle {
color: "#272822"
id: cameraRectangle
width: window.width / 2
Item {
//more stuff
}
Item {
Rectangle {
anchors.top: cameraRectangle.bottom
}
}
}
Rectangle {
//Rectangle info.
}
}
I get the error that "QML Rectangle: Cannot anchor to an item that isn't a parent or sibling." On the line where I am doing anchors.top: cameraRectangle.bottom. I would have assumed that the outer rectangle IS a parent of the inner one?
I have searched online like here: http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html and they don't seem to be doing anything differently?
Could it be the version of QtQuick I am using?
The imports are as follows:
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Material 2.0
import QtQuick.Window 2.0
I appreciate your help.
Upvotes: 3
Views: 11120
Reputation: 13691
SplitView {
anchors.fill: parent
orientation: Qt.Horizontal
Rectangle {
color: "#272822"
id: cameraRectangle
width: window.width / 2
Item {
//more stuff
}
Item {
// The parent of this Item is 'cameraRectangle'
// This Item will be the parent of the Rectangle
// therefore the Rectangle can't anchor to the 'cameraRectangle'
// anymore. As you are not doing anything with this Item
// (so far?) anway, you can just delete it, and everything
// will be fine.
Rectangle {
// The parent of this Rectangle is the Item that wraps it
// and not the 'cameraRectangle'.
anchors.top: cameraRectangle.bottom
}
}
}
Rectangle {
//Rectangle info.
}
}
As the error message stated: you can't anchor to 'ancestors' other than your parent. You can also anchor to siblings. But neither to their children, nor to yours, and not to any of your 'grand-parents', uncles or aunts ;-)
Upvotes: 5