Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListView contentY changes on move
QtWS25 Last Chance

ListView contentY changes on move

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 3.9k Views
  • 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 Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    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
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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
      0
      • E Offline
        E Offline
        ephe
        wrote on last edited by
        #3

        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
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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
          0
          • E Offline
            E Offline
            ephe
            wrote on last edited by
            #5

            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
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

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

              157

              1 Reply Last reply
              0
              • S Offline
                S Offline
                serdef
                wrote on last edited by
                #7

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved