[Interest] Change image.source onClicked with if statement function
Ramy Atalla
ramitix at yahoo.com
Wed Apr 20 16:45:08 CEST 2016
Hello I am trying to emulate a traffic light,I have four images to toggle between,I made a function to check the equality of the source image and change it on click,but it doesn't work,I think the problem in checking the equality of the source. Any ideas...ThanksRamyimport QtQuick 2.4
Item{ id:traffic_light
property string property3: "vector-traffic-light-3.png" //green property string property2: "vector-traffic-light-2.png" //yellow property string property1: "vector-traffic-light-1.png" //red property string property0: "vector-traffic-light-0.png" //off
function toggle() { if (trafficlight.source == property0) trafficlight.source = property1; else if (trafficlight.source == property1) trafficlight.source = property2; else if (trafficlight.source == property2) trafficlight.source = property3; else if (trafficlight.source == property3) trafficlight.source =property0; }
Image { id: trafficlight x: 30 y: 30 width: 43 height: 140 opacity: 0.7 source: property1
MouseArea { x: 0 y: 0
width: 43 height: 140 hoverEnabled: true onClicked:toggle() }
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160420/364f2ce4/attachment.html>
More information about the Interest
mailing list