Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListView.onAdd not being called
Qt 6.12 LTS is out! See what's new in the release blog

ListView.onAdd not being called

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 6.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have the following code (more or less) that I'm working with:

    @ListModel {
    id: tabModel
    ListElement {
    delegateText: "testing"
    }
    }

    Component {
    id: tabDelegate
    Item {
    id: delegateItem
    ListView.onAdd: SequentialAnimation {
    PropertyAction { target: delegateItem; property: "opacity"; value: 0 }
    NumberAnimation { target: delegateItem; property: "opacity"; to: 1, duration: 500; easing.type: Easing.InOutQuad }
    }
    Text {
    text: delegateText
    }
    }
    }

    ListView {
    id: tabList
    model: tabModel
    delegate: tabDelegate
    }

    function addTestElement() {
    tabModel.append({'delegateText': 'test'});
    }@

    When I dynamically add elements to the ListModel (e.g., using "addTestElement()"), they do get created, but the onAdd animation never occurs; the items simply appear, without a fade-in. What am I missing? Any help is greatly appreciated!

    (Also, I tried wrapping my code in at signs, but at least in the preview, it's still not getting syntax highlighting. I apologize!)

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Try this:
      @
      SequentialAnimation {
      id: addAnim
      PropertyAction { target: delegateItem; property: "opacity"; value: 0 }
      NumberAnimation { target: delegateItem; property: "opacity"; to: 1, duration: 500; easing.type: Easing.InOutQuad }
      }
      .....
      ListView.onAdd: {
      addAnim.start()
      }
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I appreciate the help, but unfortunately that didn't seem to change anything. I'm looking at the example in examples/declarative/modelviews/listview , and that one works fine (I've just been using qmlviewer for all of this). I can't see what the difference between that and my code is yet, but I'll keep looking!

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Odd, I just found "this thread":http://lists.qt.nokia.com/pipermail/qt-qml/2011-May/002577.html on the mailing list from a few months ago and after I commented out the width of the tabDelegate Component (not included in my minimal example above), the onAdd callback works as expected. But if the width is set, it doesn't fire. (I tested with a log statement.)

          Does anyone know why this would be so? Should I file a bug report?

          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
          • Unsolved