Important: Please read the Qt Code of Conduct -

Strange values of contentY property of ListView

  • Hi to all! I have noticed a strange behaviour of contentY property of ListView.

    And i watch for contentY property like this:

    onContentYChanged: {
        console.log( "---> " + contentY )

    1: i have a list with C++ model with 15 elements

    contentY at the top of list view is 0 (as expected)

    2: scroll this list view to bottom

    contentY at this position is 220 (as expected)

    3: click "prepend" button (i prepend 8 items to model) and scroll to top:

    And now contentY at the top of ListView is -400! But it should be 0?

    Is it qml bug or my misunderstanding?


    Is it qml bug or my misunderstanding?

    It's the latter. To cite the docs (Flickable QML Type):

    originX : real

    These properties hold the origin of the content. This value always refers to the top-left position of the content regardless of layout direction.
    This is usually (0,0), however ListView and GridView may have an arbitrary origin due to delegate size variation, or item insertion/removal outside the visible region.

    So you need to include originX, originY, contentHeight and contentWidth in your calculations.

  • @Wieland Thank you friend! It really helped me!

Log in to reply