Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Stop QML animation from c++
QtWS25 Last Chance

Stop QML animation from c++

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 4.7k Views
  • 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 Offline
    D Offline
    deimos
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        deimos
        wrote on last edited by
        #3

        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
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            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
            0
            • D Offline
              D Offline
              deimos
              wrote on last edited by
              #6

              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
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                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
                0
                • D Offline
                  D Offline
                  deimos
                  wrote on last edited by
                  #8

                  yes setProperty and invokeMethod are working.
                  thanks again

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved