ListView contentY changes on move
-
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.0ListView {
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
}@
-
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. -
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 -
Ok. Not sure then. I'd suggest you to ask this at the Qt developer mailing list.
-
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-proporiginX : 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.