[SOLVED][JS] id in parameter
-
wrote on 12 Aug 2011, 13:59 last edited by
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
-
wrote on 12 Aug 2011, 14:11 last edited by
Did you try: @onClicked: topMiddlePane.onPage(button2);@
-
wrote on 12 Aug 2011, 14:56 last edited by
Great but now the id in the chain displays the error "QDeclarativeImage(0x31326e8)On.png"
-
wrote on 12 Aug 2011, 15:16 last edited by
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";
}@ -
wrote on 12 Aug 2011, 15:23 last edited by
Yes but i have 20 buttons I can not make 20 times the process.
Do you have a other solution? I may not be the right idea
-
wrote on 12 Aug 2011, 15:25 last edited by
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"; }
}@
-
wrote on 12 Aug 2011, 16:00 last edited by
Good i love that.
Thx you and french kiss
-
wrote on 12 Aug 2011, 16:11 last edited by
Pas de souci ;-)
-
wrote on 12 Aug 2011, 16:25 last edited by
If it solved your issue, please don't forget to prepend [Solved] to the topic title.
-
wrote on 13 Aug 2011, 09:45 last edited by
You could also use the objectName property.
1/10