Results 1 to 10 of 10

Thread: SequentialAnimation created from JS not animating

  1. #1
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default SequentialAnimation created from JS not animating

    Hi all,

    I am trying to create and set animations dynamically. The animations works perfectly if statically written in original QML file. When creating animations from JS, it sucks. Nothing is animating.


    The original qml code:
    QML:
    Qt Code:
    1. Image {
    2. id: prologueImage
    3. anchors.fill: parent
    4. source: "image://encimg/prologue/splash.png"
    5. }
    6.  
    7. SequentialAnimation {
    8. running: true;
    9. PropertyAnimation {
    10. from: 0
    11. to: 1
    12. target: prologueImage
    13. duration: 2000
    14. property: "opacity"
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 


    New code:
    QML:
    Qt Code:
    1. import "PFunc.js" as PFunc
    2.  
    3. Rectangle {
    4. id: imgWrapper
    5. anchors.fill: parent
    6. Component.onCompleted: {
    7. var image = PresenterFunctions.createImage(imgWrapper);
    8. image.source = "image://encimg/prologue/splash.png";
    9.  
    10. var seqAnimation = PFunc.createSequentialAnimation(imgWrapper);
    11. var aniFIn = PFunc.createPropertyAnimation(seqAnimation, 0, 1, image, "opacity", 2000);
    12.  
    13. seqAnimation.start();
    14. }
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    JS (PFunc.js):
    Qt Code:
    1. function createImage(parent) {
    2. var image = Qt.createQmlObject("import QtQuick 2.2; Image {anchors.fill: parent; }", parent);
    3. return image;
    4. }
    5.  
    6. function createSequentialAnimation(parent) {
    7. var animation = Qt.createQmlObject("import QtQuick 2.2; SequentialAnimation {}", parent);
    8. return animation;
    9. }
    10.  
    11. function createPropertyAnimation(parent, from, to, target, prop, duration) {
    12. var animation = Qt.createQmlObject("import QtQuick 2.2; PropertyAnimation {}", parent);
    13. animation.from = from;
    14. animation.to = to;
    15. animation.target = target;
    16. animation.property = prop;
    17. animation.duration = duration;
    18. return animation;
    19. }
    To copy to clipboard, switch view to plain text mode 

    Note that dynamically created image was showing correctly.

    Platform:
    Win 8.1 Qt 5.3.1 MinGW 4.8.2 32bit

    Any ideas? Am I missing anything?

    Thanks.
    Last edited by hmasterwang; 27th July 2014 at 18:34. Reason: reformatted to look better

    Wishes.
    Afa.L Cheng

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    Maybe it is garbage collected?
    Try keeping the animation in a property.

    Have you tried just creating the property animation? I.e. without the sequential animation?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    Quote Originally Posted by anda_skoa View Post
    Maybe it is garbage collected?
    Try keeping the animation in a property.

    Have you tried just creating the property animation? I.e. without the sequential animation?

    Cheers,
    _
    Well I'm sure it's not garbage collected. I've seen those animations hanging in their parents in debug view when going out of the scope.

    I can animate a single PropertyAnimation. That works fine. Even if it is added to the SequentialAnimation

    Wishes.
    Afa.L Cheng

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    So is the problem that the sequential animation is not starting the property animation or does the sequential animation not run itself?
    I.e. does the sequential animation emit its started() and stopped() signals?

    Cheers,
    _

  5. #5
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    Quote Originally Posted by anda_skoa View Post
    So is the problem that the sequential animation is not starting the property animation or does the sequential animation not run itself?
    I.e. does the sequential animation emit its started() and stopped() signals?

    Cheers,
    _
    started() and stopped() are emitted, but what's interesting is that the order looks weird. First a stopped() is emitted, then a stopped() is emitted again, and last a started() is emitted. It happeded almost at the same time.

    Wishes.
    Afa.L Cheng

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    So it could be that the sequential animation does not know about the property animation.

    Can you try adding the property animation to the sequential animation's "animations" property?

    Probably something like

    Qt Code:
    1. var animations = [];
    2. animations.push(animation);
    3. parent.animations = animations;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    hmasterwang (28th July 2014)

  8. #7
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    Quote Originally Posted by anda_skoa View Post
    So it could be that the sequential animation does not know about the property animation.

    Can you try adding the property animation to the sequential animation's "animations" property?

    Probably something like

    Qt Code:
    1. var animations = [];
    2. animations.push(animation);
    3. parent.animations = animations;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    Works like a charm! Thanks

    Wishes.
    Afa.L Cheng

  9. #8
    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: SequentialAnimation created from JS not animating

    Why not use a component instead of the problematic JS code?
    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.


  10. #9
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SequentialAnimation created from JS not animating

    Quote Originally Posted by wysota View Post
    Why not use a component instead of the problematic JS code?
    Written here

    Quote Originally Posted by hmasterwang View Post

    I am trying to create and set animations dynamically.

    Wishes.
    Afa.L Cheng

  11. #10
    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: SequentialAnimation created from JS not animating

    Quote Originally Posted by hmasterwang View Post
    Written here
    Well... that doesn't answer my question as components are meant to do exactly that -- create objects dynamically.

    javascript Code:
    1. Component {
    2. id: animCompo
    3.  
    4. SequentialAnimation {
    5. // ...
    6. }
    7. }
    8.  
    9. //...
    10. var obj = animCompo.createObject(parent, {prop1: val1, prop2: val2, ...})
    To copy to clipboard, switch view to plain text mode 

    You can probably even use a Repeater in the component to get those property animations inside.
    Last edited by wysota; 29th July 2014 at 16:32.
    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. Animating QDockWidget
    By vajindarladdad in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2021, 17:27
  2. Animating QGraphicsPixmapItem
    By 2lights in forum Qt Programming
    Replies: 3
    Last Post: 27th August 2013, 12:59
  3. Replies: 4
    Last Post: 8th April 2013, 04:19
  4. animating a QGraphicsObject
    By tommy22 in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2013, 11:20
  5. Animating QSplashScreen
    By pssss in forum Qt Programming
    Replies: 3
    Last Post: 3rd September 2011, 11:39

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.