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
    http://s33.postimg.org/8tcx86xbz/image.png

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

    2: scroll this list view to bottom
    http://s33.postimg.org/f5x62oj7j/image.png

    contentY at this position is 220 (as expected)

    3: click "prepend" button (i prepend 8 items to model) and scroll to top:
    http://s33.postimg.org/c47avh3y7/image.png

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

    Is it qml bug or my misunderstanding?



  • Hi @FOXLISIN!

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.