Results 1 to 5 of 5

Thread: Crossfade two images in QML

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Crossfade two images in QML

    Been trying to crossfade 2 images using states and transitions but can't seem to find my newbie error. Upon clicking the image fades correctly the 1st time then from then from then on fails. Here is the code. Anyone see my error(s)

    javascript Code:
    1. Item {
    2. anchors.fill: parent
    3.  
    4. states: [
    5. State { // this will fade in rect2 and fade out rect
    6. name: "fadeInRect2"
    7. PropertyChanges { target: rect; opacity: 0}
    8. PropertyChanges { target: rect2; opacity: 1}
    9. },
    10. State { // this will fade in rect and fade out rect2
    11. name:"fadeOutRect2"
    12. PropertyChanges { target: rect;opacity:1}
    13. PropertyChanges { target: rect2;opacity:0}
    14. }
    15. ]
    16.  
    17. transitions: [
    18. Transition {
    19. to: "fadeInRect2"
    20. ParallelAnimation {
    21. NumberAnimation { properties: "opacity"; from:1;to:0;easing.type: Easing.InOutQuad; duration: 2500 }
    22. NumberAnimation { properties: "opacity"; from:0;to:1;easing.type: Easing.InOutQuad; duration: 2500 }
    23. }
    24. onRunningChanged: {
    25. if(!running) busyIndicator.running=false;
    26. }
    27. },
    28. Transition {
    29. to: "fadeOutRect2"
    30. ParallelAnimation {
    31. NumberAnimation { properties: "opacity";from:0;to:1;easing.type: Easing.InOutQuad; duration: 2500 }
    32. NumberAnimation { properties: "opacity";from:1;to:0;easing.type:Easing.InOutQuad; duration:2500}
    33. }
    34. onRunningChanged: {
    35. if(!running) busyIndicator.running=false;
    36. }
    37. }
    38. ]
    39.  
    40. Image {
    41. id: rect2
    42. smooth: true
    43. opacity: 0
    44. anchors.fill: parent
    45. onStatusChanged: {
    46. if(rect2.status===Image.Ready) {
    47. console.log('rect2 img is ready');
    48. fader.state='fadeInRect2';
    49. console.log('doing fadeInRect2');
    50. }
    51. }
    52. }
    53.  
    54. Image {
    55. id: rect
    56. smooth: true
    57. anchors.fill: parent
    58. opacity: 1
    59.  
    60. onStatusChanged: {
    61. if(rect.status===Image.Ready) {
    62. console.log('rect img is ready');
    63. fader.state='fadeOutRect2';
    64. console.log('doing fadeOutRect2');
    65. }
    66. }
    67. }
    68.  
    69. function toggle() {
    70. busyIndicator.running=true;
    71.  
    72. if(!rect2.opacity) { // load to the rect that has 0 opacity
    73. rect2.source="../../assets/red.jpg"
    74. }
    75. else {
    76. rect.source="../../assets/green.jpg"
    77. }
    78. }
    79. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 9th September 2016 at 08:13. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 17th February 2016, 15:44
  2. Replies: 1
    Last Post: 20th January 2011, 10:26
  3. Replies: 1
    Last Post: 16th November 2010, 17:45
  4. Images
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2009, 15:22
  5. Replies: 4
    Last Post: 27th July 2009, 15:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.