我知道有很多像这样的话题,我尝试从他们那里实现答案,但我仍然没有结果 .
我从qt creator那里拿了一些示例项目来玩这个 . 我玩改变qml文件的可见性(将每个文件视为其他屏幕) . 午餐后第3个屏幕我想让第二个屏幕看不见 . 这是我想在其中更改属性的代码:
MyLuncherList.qml
import QtQuick 2.0
Rectangle {
Item
{
id:ei
visible:false
clip: true
property url itemUrl
onItemUrlChanged:
{
visible = (itemUrl== '' ? false : true);
}
anchors.fill: parent
anchors.bottomMargin: 40
Rectangle
{
id:bg
anchors.fill: parent
color: "white"
}
MouseArea
{
anchors.fill: parent
enabled: ei.visible
//takes mouse events
}
Loader
{
focus:true
source: ei.itemUrl
anchors.fill: parent
}
}
}
这是我想要采取行动的代码
View2.qml
import QtQuick 2.0
Rectangle {
width: 100
height: 62
Text
{
text: "second screen"
}
MyLuncherList
{
id:luncherList
}
Rectangle
{
x: 50
y: 30
width: 120
height: 60
color: "red"
MouseArea
{
anchors.fill: parent
id: mouseAreaWhichHides
onClicked:
{
luncherList.ei.itemUrl = '';
}
}
}
}
我得到了错误: qrc:///View2.qml:29: TypeError: Type error
这一点上的这一点 luncherList.ei.itemUrl = '';
类型错误说我与Type有些不匹配,但我甚至不确定,如果我以正确的方式执行此访问过程,那么我问的是如何改变的 property
ei.itemUrl
从
View2.qml
在工作方式 .
1 回答
ei 元素将无法直接在其他QML文件中使用 . 您可以使用别名来执行此操作 .
并从其他QML文件中调用它