how to find property color and change value for Text element in my qtquick project?
content on my.qml file.
Rectangle {
width: 300
height: 200
Text {
x: 12
y: 34
color:red
}
}
A property is an attribute of an object that can be assigned a static value or bound to a dynamic expression. A property's value can be read by other objects. Generally it can also be modified by another object, unless a particular QML type has explicitly disallowed this for a specific property.
Property bindings are a core feature of QML that lets developers specify relationships between different object properties. When a property's dependencies change in value, the property is automatically updated according to the specified relationship.
Unlike an ordinary property definition, which allocates a new, unique storage space for the property, a property alias connects the newly declared property (called the aliasing property) as a direct reference to an existing property (the aliased property).
The QtObject type is a non-visual element which contains only the objectName property. It can also be useful for C++ integration, as it is just a plain QObject.
you need to set objectName property like below:
Rectangle {
width: 300
height: 200
Text {
objectName: "text1"
x: 12
y: 34
color: "red"
}
}
now you can find and access to element and property.
for example, i find color in Text element and change to green:
view = QDeclarativeView(QUrl('widget.qml'),parent = object)
property = QDeclarativeProperty(view.rootObject().findChild(QDeclarativeItem, name="text1"),"color")
property.write("green")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With