无法锚定到不是父级或兄弟级 QML QtQuick 的项目 [英] Cannot anchor to an item that isn't a parent or sibling QML QtQuick
问题描述
我正在使用 QML 开发 Python 桌面应用程序.
I'm working on a python desktop app using QML.
我的 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.
}
}
我收到QML 矩形:无法锚定到非父项或兄弟项的项目"的错误消息.在我做 anchors.top 的那一行:cameraRectangle.bottom.我会假设外部矩形是内部矩形的父级吗?
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?
我像这里一样在线搜索:http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html 他们似乎没有做任何不同的事情?
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?
会不会是我使用的 QtQuick 版本?
Could it be the version of QtQuick I am using?
导入如下:
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
感谢您的帮助.
推荐答案
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 ;-)
这篇关于无法锚定到不是父级或兄弟级 QML QtQuick 的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!