Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Stop QML animation from c++

    QML and Qt Quick
    2
    8
    4277
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      deimos last edited by

      Hi,

      I have made a custom component subclassing QDeclarativeItem.
      In QML I have for example:

      @
      MyItem {
      Behavior on x { NumberAnimation { duration: 1500 } }
      [...]
      }@

      I would like to stop all the animations without using some binding QML code inside MyItem just because it will be a plugin and I don't want the user to take care of this.
      I seen that Behaviour isn't a QDeclarativeItem , it is a QAbstractAnimation if I remember well. So if I parse all childrens of MyItem (in c++), it is not listed and I cant call the stop() function. But maybe I am wrong.
      Any idea ?

      thanks in advance and happy new year :)
      Marco

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Maybe adding id to this behaviour would improve things? If no, you can try writing this a bit differently:
        @
        MyItem {
        NumberAnimation on x { duration: 1500 }
        [...]
        }
        @
        That might work.

        Both are just guesses, though. In my code, I handle animations with JS.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • D
          deimos last edited by

          thank sierdzio for the replay.

          My wishes is to call "complete()":http://developer.qt.nokia.com/doc/qt-4.8/qml-animation.html#complete-method for all animations inside c++. In your code example, I found this:

          @QObject *item;
          foreach (item, children() )
          qDebug() << item->metaObject()->className(); @

          the output is "QDeclarativeNumberAnimation". This is a class derived from QDeclarativeAbstractAnimation.
          I would like for example to call:

          @qobject_cast<QDeclarativeAbstractAnimation*>(item)->complete();@

          but QDeclarativeAbstractAnimation is private and I think this could not be achieved without some binds in QML.

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            What about:
            @
            // QML
            MyItem {
            NumberAnimation on x { alwaysRunToEnd: true; duration: 1500 }
            [...]
            }

            // C++
            item.setProperty("running", QVariant(false));
            @

            Or, try casting to QDeclarativeNumberAnimation - if it exists. I am sure there was some example on how to access animations from C++ in QML documentation, but I can't find it now.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • sierdzio
              sierdzio Moderators last edited by

              Ah, I've found it. Should help: "LINK":http://developer.qt.nokia.com/doc/qt-4.8/qtbinding.html#calling-functions

              (Z(:^

              1 Reply Last reply Reply Quote 0
              • D
                deimos last edited by

                QDeclarativeNumberAnimation is private also :( , but you gave me some useful reminds that make me try to continue. The "alwaysRunToEnd" makes the animation to terminate but it is animated till it ends, but maybe I can bypass this with something other.

                For your consideration I made this "video":http://www.youtube.com/watch?v=-y8boYYCsc4 : at 48" , when I press "menu 3" and then a sub menu, I would like to terminate all animations in the first one otherwise unwanted behavior should happens if sub menu is open before animations end (ops, maybe I been unclear with this sentence, but video explains :) ).

                thanks again

                1 Reply Last reply Reply Quote 0
                • sierdzio
                  sierdzio Moderators last edited by

                  I'll think about it later, currently I'm deep into an algorithm I'm writing any my brain is steaming :)

                  Just to clarify, though: have you tried using item->setProperty() or item->invokeMethod() without casting? I think it should work, but - as I've mentioned - my cognitive powers are diminished at the moment :)

                  (Z(:^

                  1 Reply Last reply Reply Quote 0
                  • D
                    deimos last edited by

                    yes setProperty and invokeMethod are working.
                    thanks again

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post