无法锚定到不是父项或同级 QML QtQuick 的项目
Cannot anchor to an item that isn't a parent or sibling QML QtQuick
我正在使用 QML 开发 python 桌面应用程序。
我的 QML 文件中有这个:
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 Rectangle: Cannot anchor to an item that isn't a parent or sibling." 在我正在做的行 anchors.top:cameraRectangle.bottom。我会假设外部矩形是内部矩形的父矩形吗?
我像这里一样在线搜索:http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html 他们似乎没有做任何不同的事情?
会不会是我用的QtQuick版本问题?
导入如下:
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.
}
}
如错误消息所述:除了您的 parent,您无法锚定到 'ancestors'。您也可以锚定到兄弟姐妹。但他们 children 和你的 'grand-parents',叔叔阿姨都不会;-)
我正在使用 QML 开发 python 桌面应用程序。
我的 QML 文件中有这个:
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 Rectangle: Cannot anchor to an item that isn't a parent or sibling." 在我正在做的行 anchors.top:cameraRectangle.bottom。我会假设外部矩形是内部矩形的父矩形吗?
我像这里一样在线搜索:http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html 他们似乎没有做任何不同的事情?
会不会是我用的QtQuick版本问题?
导入如下:
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.
}
}
如错误消息所述:除了您的 parent,您无法锚定到 'ancestors'。您也可以锚定到兄弟姐妹。但他们 children 和你的 'grand-parents',叔叔阿姨都不会;-)