[SOLVED][JS] id in parameter
-
Hi,
I have main.qml.
@import Qt 4.7Item {
id: topMiddlePaneImage { id: buttonClasse source: "pict/button1Off.png" x: 329 y: 0 width: 123 height: 52 opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onClicked: topMiddlePane.onPage("button1"); } } Image { id: button2 source: "pict/button2Off.png" x: 210 y: 0 width: 111 height: 52 opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onClicked: topMiddlePane.onPage("button2"); } function onPage(id){ id.source = "pict/"+id+"On.png"; }
}@
I want to switch source according to the value of my parameter (to onPage function).
But my problem is that QML seeks id.source and not bouton1.source
Do you have a solution?sorry for my English
-
That's because the id is not a string nor a regular variable.
[quote]The id value is a special value for a QML object and should not be thought of as an ordinary object property; [/quote] "link to doc":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeintroduction.html#object-identifiersWhat might be a solution:
@function onPage(id){
id.source = (id == button1)? "pict/button1On.png": "pict/button2On.png";
}@ -
Or else:
@Image {
id: button2
property string name: "button2"
source: "pict/button2Off.png"
x: 210
y: 0
width: 111
height: 52
opacity: 1MouseArea { anchors.fill: parent hoverEnabled: true onClicked: topMiddlePane.onPage(id); } function onPage(id){ id.source = "pict/"+id.name+"On.png"; }
}@