Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    ListView contentY changes on move

    QML and Qt Quick
    3
    7
    2980
    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.
    • E
      ephe last edited by

      When clicking an item in the ListView, it should be moved to the first implementation.
      I wanted to animate the opacity, but it seems not to be possible. Then I saw that the contentY of the listView changes, the moved item is at contentY -105.
      Am I doing something wrong, is this the desired behaviour or is it a bug?

      @
      import QtQuick 2.0

      ListView {
      id: listView
      width: 300;
      height: 350
      model: ListModel
      {
      ListElement{borderColor: "red"}
      ListElement{borderColor: "blue"}
      ListElement{borderColor: "green"}
      ListElement{borderColor: "yellow"}
      ListElement{borderColor: "purple"}
      ListElement{borderColor: "pink"}
      ListElement{borderColor: "red"}
      ListElement{borderColor: "grey"}
      }
      onContentYChanged: console.log("contentY: " + contentY)
      spacing: 5
      delegate: Rectangle {
      width: 200
      height: 100
      border.width: 2
      border.color: borderColor
      MouseArea
      {
      anchors.fill: parent
      onClicked: listView.model.move(index, 0, 1)
      }
      }
      cacheBuffer: 150*count
      }

      @

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi,

        Sorry, but can you elaborate the problem clearly ?
        When you move the item, i think it's obvious that the y position would change.
        On the side note, Can you try "PathView":http://qt-project.org/doc/qt-5/qml-qtquick-pathview.html ? I think it fits your requirement.

        157

        1 Reply Last reply Reply Quote 0
        • E
          ephe last edited by

          It is clear for me that the contentY will change, but I am wondering why it changes to a negative value. I would think that the move operation always moves it to 0 or a positive pixel position

          1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators last edited by

            Hi,

            I think it does actually set it to 0. I tested it as follows:
            @
            onClicked: {
            listView.model.move(index, 0, 1);
            currentIndex = index;
            positionViewAtIndex(index,ListView.Beginning);
            console.log("C.Y:",contentY)
            }
            @
            The negative value is seen when you move the item by mouse by clicking on it and then dragging down. This i think is due to the boundsBehavior which has Flickable.DragAndOvershootBounds as default and hence it overshoots a little bit. Try setting it to Flickable.StopAtBounds and contentY would always be > 0

            157

            1 Reply Last reply Reply Quote 0
            • E
              ephe last edited by

              Thank you for your answer!
              I also tried your code, but for me it still shows contentY < 0 when I scroll up.

              I just tried setting the Flickable.StopAtBounds, but sadly the contentY is still < 0

              1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators last edited by

                Ok. Not sure then. I'd suggest you to ask this at the Qt developer mailing list.

                157

                1 Reply Last reply Reply Quote 0
                • S
                  serdef last edited by

                  Hi,

                  yes this is documented behaviour :

                  The top postion of a flickable is defined by originY and this can be a negative number :

                  check it out here :
                  http://qt-project.org/doc/qt-5/qml-qtquick-flickable.html#originY-prop

                  originX : real
                  originY : 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 should use the originY value as the start position, instead of 0.
                  OriginY can be negative, but should work fine as long as you take that into account in your calculations.

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