Results 1 to 13 of 13

Thread: SequentialAnimation dont work - why?!?

  1. #1
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default SequentialAnimation dont work - why?!?

    I want rectangle animation from y = 0; to y = baza.height - rect1.height. I follow examples, but with no effect. Can you tell me why?
    My code is as follow:
    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.4
    4.  
    5. Window {
    6. visible: true
    7. title: qsTr("Hello World")
    8. visibility: Window.Maximized
    9. Rectangle
    10.  
    11. {
    12. id: baza
    13. x: 0
    14. y: 0
    15. width: parent.width
    16. height: parent.height
    17.  
    18. Rectangle
    19. {
    20. id: rect1
    21. x: 0
    22. y: 0
    23. width: 9
    24. height: 100
    25. radius: width / 2
    26. color: "blue"
    27. //color: { if (width > 20) "blue"; else "red" }
    28.  
    29. //SequentialAnimation {
    30. SequentialAnimation{
    31.  
    32. loops: Animation.Infinite
    33. running: true
    34. NumberAnimation { target: rect1; property: "y"; to: { baza.height - rect1.heigh; } duration: 3000 }
    35. }
    36. }
    37.  
    38.  
    39. MouseArea
    40.  
    41. {
    42.  
    43. anchors.fill: baza
    44.  
    45. onClicked:
    46.  
    47. {
    48. Qt.quit();
    49.  
    50. }
    51.  
    52. }
    53.  
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 

  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 dont work - why?!?

    Does this run without a warning?

    My guess is that trying to set an object for the "to" value just leaves the "to" value at is default, 0.

    Your animation is also missing a "from" value, so even if you pass a valid "to" value it will only have a visual effect once.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Exclamation Re: SequentialAnimation dont work - why?!?

    Please try run my qml and figure out what is wrong. I corrected code and it is still not working, it is as follow:
    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.4
    4.  
    5. Window {
    6. visible: true
    7. title: qsTr("Hello World")
    8. visibility: Window.Maximized
    9. Rectangle
    10.  
    11. {
    12. id: baza
    13. x: 0
    14. y: 0
    15. width: parent.width
    16. height: parent.height
    17.  
    18. Rectangle
    19. {
    20. id: rect1
    21. x: 0
    22. y: 0
    23. width: 9
    24. height: 100
    25. radius: width / 2
    26. color: "blue"
    27.  
    28. SequentialAnimation on y {
    29. loops: Animation.Infinite
    30. running: true
    31. NumberAnimation { from: 0; to: { baza.height - rect1.heigh; } easing.type: Easing.OutExpo; duration: 3000 }
    32. }
    33. }
    34.  
    35.  
    36.  
    37. MouseArea
    38.  
    39. {
    40.  
    41. anchors.fill: baza
    42.  
    43. onClicked:
    44.  
    45. {
    46. Qt.quit();
    47.  
    48. }
    49.  
    50. }
    51.  
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: SequentialAnimation dont work - why?!?

    Qt Code:
    1. NumberAnimation { from: 0; to: { baza.height - rect1.heigh; } easing.type: Easing.OutExpo; duration: 3000 }
    To copy to clipboard, switch view to plain text mode 

    Shouldn't there be a semicolon between your 'to' and 'easing.type'?
    And 'height' is misspelled after rect1.

    --SamG

  5. #5
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Exclamation Re: SequentialAnimation dont work - why?!?

    Thanks scgrant327 ! I corrected rect1.height. And semicolon between to and easing.type will be wrong and wont compile.
    Is there any option for compiler to show undefined properties (like rect1.heigh)?
    Now it compile and works but it seems to decease "y" instead grow. So animation is upwards screen instead downwards screen. It is strange because I clearly typed animation from y=0 to y = baza.height - rect1.height which later mean something like y = 1100 - 100 so I don't suspect negative value for to:
    Now corrected code is as follow:
    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.4
    4.  
    5. Window {
    6. visible: true
    7. title: qsTr("Hello World")
    8. visibility: Window.Maximized
    9. Rectangle
    10.  
    11. {
    12. id: baza
    13. x: 0
    14. y: 0
    15. width: parent.width
    16. height: parent.height
    17.  
    18. Text
    19. {
    20. id: log1
    21. anchors.centerIn: parent
    22. text: "Type something..."
    23. }
    24.  
    25. Rectangle
    26. {
    27. id: rect1
    28. x: 100
    29. y: 100
    30. width: 9
    31. height: 100
    32. radius: width / 2
    33. color: "blue"
    34.  
    35. function calculateY() {
    36. log1.text = "baza.height: %1, baza.height - height: %2".arg(baza.height).arg(baza.height - this.height);
    37. return baza.height - this.height; // == 1047
    38. }
    39.  
    40. SequentialAnimation on y {
    41. loops: Animation.Infinite
    42. running: true
    43. // NumberAnimation { from: 0; to: 1047; easing.type: Easing.OutExpo; duration: 3000 } // \ that works as expected
    44. // NumberAnimation { from: 1047; to: 0; easing.type: Easing.OutExpo; duration: 3000 } // /
    45. NumberAnimation { from: 0; to: rect1.calculateY(); easing.type: Easing.OutExpo; duration: 3000 } // \ not works == animated upwards instead downwards
    46. NumberAnimation { from: rect1.calculateY(); to: 0; easing.type: Easing.OutExpo; duration: 3000 } // /
    47. }
    48. }
    49.  
    50. MouseArea
    51. {
    52. anchors.fill: baza
    53. onClicked: { Qt.quit(); }
    54. }
    55. }
    56. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Szyk; 7th December 2016 at 16:31.

  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 dont work - why?!?

    Quote Originally Posted by Szyk View Post
    Thanks scgrant327 ! I corrected rect1.height. And semicolon between to and easing.type will be wrong and wont compile.
    No, scgrant327 was right, there was a missing separate between those two properties.

    And, as I wrote, put a number into "to", why on earth do you have {} there?

    You could have jsut removed those and it would have fixed your animation's "to" value and the missing separator.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: SequentialAnimation dont work - why?!?

    @anda_skoa
    Thanks for your reply. But as you can see in my previous post I have changed javascript expression to function call. And it is not work. Simple typing to: 1047; value works but to: rect1.calculateY(); does not work! Should I type Qt.binding(rect1.calculateY()) ? It seems Qt.binding wokrs only for lambda functions...

  8. #8
    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 dont work - why?!?

    Should also work with a function, but you likely need to remove the "this." part.

    Not sure why you want to do this more complicated than necessary, but that is of course your choice.

    Cheers,
    _

  9. #9
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Exclamation Re: SequentialAnimation dont work - why?!?

    @anda_skoa:
    I removed "this", but still no luck... Did you try my code?!? Now it animated rounded rectangle height (rect1.height) from 100 to 0. But I want animation that rectangle from y=0 to y=parent.height - rect.height and back without change its height. It is strange that it is difficult to do so silly thing! I started thinking that it is bug in Qt! Maybe you can write sample working code?
    Thanks...
    Last edited by Szyk; 9th December 2016 at 15:23.

  10. #10
    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 dont work - why?!?

    Well, additional to the {} which should not be there, as I wrote before, you had a typo in the property "rect1.heigh" (missing "t")

    I fixed those and added the second animation and to no suprise it works.

    Qt Code:
    1. SequentialAnimation on y {
    2. loops: Animation.Infinite
    3. running: true
    4. NumberAnimation {
    5. from: 0; to: baza.height - rect1.height; easing.type: Easing.OutExpo; duration: 3000
    6.  
    7. }
    8. NumberAnimation {
    9. to: 0; easing.type: Easing.OutExpo; duration: 3000
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    No bug in Qt you see, just buggy code.

    Cheers,
    _

  11. #11
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: SequentialAnimation dont work - why?!?

    I have Qt5.6.1 and it animate rec1.height not rect1.y!!! Did you notice that?!?

  12. #12
    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 dont work - why?!?

    It doesn't animate height, it animates y. You could have checked by logging the value in onYChanged.

    Doing that you could have found out that apparently the "to" value is negative.
    Could have concluded that the window has height 0 initially, thus baza has height 0 initially, thus the to value being -100 initially.

    One attempt to address that could have been to not run the animation until the resulting to value is greater than 0, e.g.
    Qt Code:
    1. readonly property real toValue: baza.height - rect1.height
    2. SequentialAnimation on y {
    3. loops: Animation.Infinite
    4. running: rect1.toValue > 0
    5. NumberAnimation {
    6. from: 0; to: rect1.toValue; easing.type: Easing.OutExpo; duration: 3000
    7.  
    8. }
    9. NumberAnimation {
    10. to: 0; easing.type: Easing.OutExpo; duration: 3000
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  13. #13
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: SequentialAnimation dont work - why?!?

    @anda_skoa:
    Thank you now it works!
    It seems to be classic problem (gui race)...

Similar Threads

  1. QGesture dont work
    By Talei in forum Qt Programming
    Replies: 0
    Last Post: 21st December 2013, 17:55
  2. QWidget -> updateGeometry dont work.
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 22nd May 2013, 15:55
  3. Replies: 3
    Last Post: 9th October 2012, 02:12
  4. Dont work replot() after using zoom
    By ruzik in forum Qwt
    Replies: 2
    Last Post: 25th September 2011, 09:26
  5. Problem with QtBrowserPlugin - examples dont work.
    By robert_ugo in forum Installation and Deployment
    Replies: 0
    Last Post: 19th March 2009, 19:07

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.