Results 1 to 9 of 9

Thread: QML PropertyAnimation & StackView

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

    Unhappy QML PropertyAnimation & StackView

    Developing for Android. QT 5.6.

    I have a StackView in my main.qml to load each of my sub-pages on demand. It's elegant, and works flawlessly. All my bindings allow data propagation without issues.

    However, I have some C++ code that updates the QML with the user's location via property bindings. I have an Image type on one QML page that has a Glow and PropertyAnimation. This page is loaded via the StackView on app startup.

    Qt Code:
    1. Glow {
    2. id: statusGlow
    3. anchors.fill: statusImage
    4. radius: 16
    5. samples: 33
    6. spread: 0.85
    7. color: appWin.statusGlowColor
    8. source: statusImage
    9. visible: appWin.statusGlowVisible
    10. opacity: appWin.statusGlowOpacity
    11. }
    12. PropertyAnimation {
    13. id: statusAnimation
    14. target: statusGlow
    15. property: "opacity"
    16. from: 100
    17. to: 0
    18. duration: 500
    19. running: appWin.statusAnimationRunning
    20. }
    21. Image {
    22. id: statusImage
    23. anchors.fill: parent
    24. fillMode: Image.PreserveAspectFit
    25. antialiasing: true
    26. source: "status.png"
    27. sourceSize.width: 715
    28. sourceSize.height: 1543
    29. smooth: false
    30. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, I am connecting the properties of the Glow and PropertyAnimation to variables in my main.qml (appWin). The C++ code updates those variables and calls a function in main.qml to 'enable' the Glow and PropertyAnimation:

    Qt Code:
    1. function gpsUpdate2() {
    2. if( !runningBackground ) {
    3. statusGlowColor = "yellow";
    4. statusGlowOpacity = 100;
    5. statusGlowVisible = true;
    6. statusAnimationRunning = true;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Problem is, this only works the FIRST time that 'gpsUpdate2' is called. On subsequent calls to 'gpsUpdate2', the Glow does not appear...Why?

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QML PropertyAnimation & StackView

    I can tell you that in the function gpsUpdate2() you're assing values, so the binding are broke
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

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

    Default Re: QML PropertyAnimation & StackView

    Quote Originally Posted by john_god View Post
    I can tell you that in the function gpsUpdate2() you're assing values, so the binding are broke
    I think you are incorrect on that.. the 'gpsUpdate2' function is IN my main.qml, where the variables reside. The BINDINGS are in MainWin.qml, which is loaded via StackView.

    The variables are declared in main.qml:

    Qt Code:
    1. property string statusGlowColor: "limegreen"
    2. property bool statusGlowVisible: false
    3. property int statusGlowOpacity: 100
    4. property bool statusAnimationRunning: false
    To copy to clipboard, switch view to plain text mode 

  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: QML PropertyAnimation & StackView

    Aside from your insistance on using hacks to interact with C++ there are two observations:

    1) opacity is a value between 0 and 1, so 100 is a rather weird value
    2) where in the code do you set statusAnimationRunning to false after you had set it to true?

    Cheers,
    _

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

    scgrant327 (13th May 2016)

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

    Lightbulb Re: QML PropertyAnimation & StackView

    Quote Originally Posted by anda_skoa View Post
    Aside from your insistance on using hacks to interact with C++ there are two observations:
    I'm not using any 'hacks' for interacting with C++... it's all pure property binding now.

    Quote Originally Posted by anda_skoa View Post
    1) opacity is a value between 0 and 1, so 100 is a rather weird value
    Well, that does make some sense... but again... I've ALWAYS used 100 as the initial value, and it worked before StackView. Hmmmm. I'll make sure to use 1 instead of 100 and see if it appears different.

    Quote Originally Posted by anda_skoa View Post
    2) where in the code do you set statusAnimationRunning to false after you had set it to true?
    Ahhhh... you are correct. I never reset the 'running' flag.... Odd thing is, I have NEVER reset that flag to false. And this USED to work before I starting using StackView. I was assuming that the 'running' flag was auto-set to false once the animation was completed.

  7. #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: QML PropertyAnimation & StackView

    Quote Originally Posted by scgrant327 View Post
    I'm not using any 'hacks' for interacting with C++... it's all pure property binding now.
    You wrote "The C++ code updates those variables and calls a function in main.qml", so I assumed you meant calling a QML function from C++.
    If you are no longer doing that hack you should be fine

    Quote Originally Posted by scgrant327 View Post
    Ahhhh... you are correct. I never reset the 'running' flag.... Odd thing is, I have NEVER reset that flag to false. And this USED to work before I starting using StackView. I was assuming that the 'running' flag was auto-set to false once the animation was completed.
    The animation's own state is probably false, but since your property never is false ever again, it never changes when your function sets it to true, so the binding doesn't get reevaluated.

    My suggestion would be to either reset the property in the animation's onStopped handler, or to remove the property and calling start() on the animation instead.

    Cheers,
    _

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

    Default Re: QML PropertyAnimation & StackView

    I'll try resetting the property in the onStopped handler... As I'm not sure how to call the 'start' method on an animation that exists on a page loaded by the StackView...

  9. #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: QML PropertyAnimation & StackView

    Quote Originally Posted by scgrant327 View Post
    As I'm not sure how to call the 'start' method on an animation that exists on a page loaded by the StackView...
    Right.
    Your main object could emit a signal and in the page element you could then use a Connection element to react to that.

    Like you most likely already handle the signal from C++ that triggers the call to gpsUpdate2() (assuming you have, as you claim, moved away from the hack of calling QML functions from C++).

    Cheers,
    _

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

    Default Re: QML PropertyAnimation & StackView

    Thanks again Anda. Resetting via the onStopped handler worked perfectly.

    --Sam

Similar Threads

  1. interaction StackView / ListView
    By RegMe in forum Qt Quick
    Replies: 11
    Last Post: 18th January 2016, 20:06
  2. StackView get index or views page
    By KeineAhnung in forum Newbie
    Replies: 2
    Last Post: 18th November 2014, 23:03
  3. Any example of StackView?
    By stereoMatching in forum Qt Quick
    Replies: 1
    Last Post: 16th December 2013, 09:07

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.