我需要在父qml中使用我的大多数孩子qml孩子,所以使用别名我现在正在做,但有些我怎么称呼 login.help.visible 太多点。可能有人给我最好的解决方案。
这是我的代码
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
Widget{
id: login
}
MouseArea{
anchors.fill: parent
onClicked: login.help.visible = false
onEntered: {
login.help.visible = true
login.progress.visible = true
ogin.pwd.visible = true
}
onExited: {
login.help.visible = false
login.progress.visible = false
ogin.pwd.visible = false
}
}
}
}
Widget.qml
import QtQuick 2.0
import QtQuick.Controls 1.2
Item {
id: newid
property alias help: helpid
property alias progress: ploder
property alias username: name
property alias password: pwd
Help{
id: helpid
}
TextCustom{
id: name
}
TextCustom{
id: pwd
}
progressLoader{
id: ploder
}
}
答案 0 :(得分:0)
通常,一旦我定义了一个新的Component
,我就会通过将所有东西隐藏到用户来封装它的子,逻辑和属性,同时我公开了可自由修改的属性(甚至是那些属于我的组件的子项)通过其属性(也称为property
关键字,正确绑定到组件或其子组件的目标属性)。
这样,我的组件的子项与组件本身的用户很好地隔离。
它是一个例子:
// MyComponent.qml
Item {
property alias B: firstChild.B
Item {
id: firstChild
property int A: 0 // this is hidden to the users of MyComponent...
property int B: 0 // ... this is not, indeed
}
}
// AnotherComponent.qml
// the outer Component has the following child
MyComponent {
B: 3 // directly modifies the property B of firstChild in MyComponent
}