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. (solved) animating a dynamically created qml component
Forum Updated to NodeBB v4.3 + New Features

(solved) animating a dynamically created qml component

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jsprenkle
    wrote on last edited by
    #1

    Good morning,

    I'm doing a custom table view object in C++. It's working but I'd like to improve how it's displayed. I created a component with animations attached to it. It creates the component and it displays correctly but the animations don't work.

    @ myTableView
    {
    // provide an item the control can use for positioning. Exposed so visual effects can be attached
    Component
    {
    id: gridPositionerId
    Item
    {
    // Apply a NumberAnimation x property changes
    Behavior on x
    {
    NumberAnimation
    {
    duration: 12000
    easing.type: Easing.InOutQuad
    }
    }
    Behavior on y
    {
    NumberAnimation
    {
    duration: 12000
    easing.type: Easing.InOutQuad
    }
    }
    }
    }
    // tell the view what to use for a positioner
    positioner: gridPositionerId
    }
    @

    The instance of the positioner is created like this:

    @ // create instance of positioner
    positioner = qobject_cast< QQuickItem* >( _Positioner->create() );
    if ( ! positioner )
    {
    qCritical() << "Cannot create a valid Positioner item";
    return;
    }
    // set visual parent
    positioner->setParentItem( this );
    @

    I manage the position in the C++ code.

    @positioner->setX( 10 );@

    Any ideas why the behaviors aren't triggered?
    The qdebug output doesn't show any errors

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      From the Docs "here":http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#accessing-members-of-a-qml-object-type-from-c

      bq. You should always use QObject::setProperty(), QQmlProperty or QMetaProperty::write() to change a QML property value, to ensure the QML engine is made aware of the property change.

      So instead of using setX, try using one of the above.

      157

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsprenkle
        wrote on last edited by
        #3

        I completely missed that in the docs. I just assumed we were supposed to use the accessor methods. I guess that's the Qt4 way and the not the QQuick way.

        :)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jsprenkle
          wrote on last edited by
          #4

          You were exactly correct. Thanks again for the help

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            You're Welcome :) Please mark the post as solved.

            157

            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