【发布时间】:2013-02-03 01:19:49
【问题描述】:
如何在我的 qtquick 项目中找到属性 color 并更改 Text 元素的值?
my.qml 文件中的内容。
Rectangle {
width: 300
height: 200
Text {
x: 12
y: 34
color:red
}
}
【问题讨论】:
如何在我的 qtquick 项目中找到属性 color 并更改 Text 元素的值?
my.qml 文件中的内容。
Rectangle {
width: 300
height: 200
Text {
x: 12
y: 34
color:red
}
}
【问题讨论】:
你需要像下面这样设置 objectName 属性:
Rectangle {
width: 300
height: 200
Text {
objectName: "text1"
x: 12
y: 34
color: "red"
}
}
现在您可以查找和访问元素和属性。
例如,我在 Text 元素中找到颜色并更改为绿色:
view = QDeclarativeView(QUrl('widget.qml'),parent = object)
property = QDeclarativeProperty(view.rootObject().findChild(QDeclarativeItem, name="text1"),"color")
property.write("green")
【讨论】: