Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved Strange values of contentY property of ListView

    QML and Qt Quick
    2
    3
    733
    Loading More Posts
    • 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.
    • F
      FOXLISIN last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by A Former User

        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.

        F 1 Reply Last reply Reply Quote 0
        • F
          FOXLISIN @Guest last edited by FOXLISIN

          @Wieland Thank you friend! It really helped me!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post