Results 1 to 4 of 4

Thread: QML Animation

  1. #1
    Join Date
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QML Animation

    I have an application where I want to show animation using QML for n seconds.
    For e.g I want to change the size of rectangle for each second.The input will be an array storing size of the rectangle at each second.

    input[5] ={10,20,30,5,9}

    In this case I want to run simulation for 5 second for different sizes.
    Initally the size of rectangle will be height=width=input[0].
    On completion of a second the height=width=input[1] and so on.

    I dont want to hardcode here as the input will be dynamic.
    I am new to QML so don't know whether this requirement is possible to implement with QML.

    Can anybody help me in this?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Animation

    Create a SequentialAnimation component and add your animations there. Have a look at Dynamic Object Management in QML for information how to create objects on the fly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QML Animation

    Hi,
    As per my understanding SequentialAnimation works on some property/attribute of QML object. For e.g. width/height of rectangle object. It keeps the property incrementing to some limit.
    But in my case the value of the property(width/height) is defined in an array. So how I can apply SequentialAnimation in this case.

    Currently I am able to create the objects dynamically but not able to show the animation.

    main.qml -
    javascript Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: container
    5. width: 1500; height: 1000
    6.  
    7.  
    8. Component.onCompleted: {
    9. var component = Qt.createComponent("rectangle.qml");
    10.  
    11. // Define an array
    12. var sim_data = new Array(3); // 10 rectangles for 3 secs
    13. var t = 0;
    14. for(var i = 0;i<3;i++)
    15. sim_data[i] = new Array(10);
    16.  
    17. sim_data[0]= [0.000000,0.098023,0.192176,0.282582, 0.369357,0.452661,0.532547,0.609014,0.682063,0.751692,0.817902];
    18. sim_data[1]= [10.000000,9.900498,9.801986, 9.704455,9.607893,9.512226,9.417414,9.323457,9.230357,9.138112,9.046724];
    19. sim_data[2]= [0.000000,0.000493,0.001946,0.004321,0.007583,0.011704, 0.016680,0.022509,0.029193,0.036732];
    20.  
    21.  
    22. var col = ["red","yellow","green","blue","black"];
    23.  
    24. // working
    25.  
    26. for(var t=0; t < 3; t++)
    27. {
    28. var y = 100 * t + 150;
    29. console.log("At t = ", t);
    30.  
    31. for (var i=0; i<10; i++)
    32. {
    33. var object = component.createObject(container);
    34. object.width = sim_data[t][i] + 100;
    35. object.height = sim_data[t][i] + 100;
    36.  
    37. console.log("width = ", object.width);
    38. console.log("height = " ,object.height);
    39. object.x = 150 * i;
    40. object.y = 100;
    41. object.color = col[t];
    42. }
    43. }
    44.  
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    rectangle.qml -

    javascript Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. id: rect
    5. color:"Red"
    6. }
    To copy to clipboard, switch view to plain text mode 


    Thanks.
    Last edited by wysota; 11th August 2011 at 09:13. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML Animation

    So you don't want the animation to be smooth? If so, then simply use a timer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Question about animation
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2010, 00:56
  2. png not support animation in QT4.6
    By sophister in forum Qt Programming
    Replies: 6
    Last Post: 10th December 2009, 14:04
  3. Animation in Qt
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 08:05
  4. Animation in Qt
    By yogesh884 in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2009, 10:56
  5. QPainter and Animation
    By miker in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2006, 04:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.