Unsolved ContentX in ListView switches back to 0 when model is updated.
-
Hi,
I have a tableView and a ListView in my qml.
The ContentX of the ListView is mapped to the contentX of the tableview.But when the model is updated , even though the contentX of tableview comes a positive number, the contentX of the Listview switches back to 0.
Is there a different solution where i can match the contentX of the List view to the contentX of the TableView ?
-
@Anita very hard to tell without knowing how exactly you do this. Can you show your code?
-
@Anita hi
the ListView doc says
It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates.Try to use positionViewAtIndex method
-
@J-Hilk
Hi,
I cannot post the code, but the requirement is such as follows:- The List View is horizontally oriented which is placed below the table view.
- The width of the List View and the tableView is the same.
- The No. of coloumns of the tableview is same as the no of elements in the List view.
- The width of each of the column of the table view is the same as that of the delegate width of the List View.
- The List view is not interactive.
- The List View should be synched with the horizontal movement of the tableview.
All of these requirements where achieved , and the 4th requirement is achieved by managing the contentX of the listview maching the contentX of the tableview.
But when a new entry is added in the model of the tableview and the ListView, the contentX of the Listview switches back to 0 even if the contentX of the tableview is a positive no.
-
@LeLev
Hi LeLev,The issue is I have to synch the tableview and the ListView positions.
So if we scroll the tableview, the listview also should scroll. So In that case i will need to know the index of the tableview as well. as i wouldnt know the current Index of the TableView. -
Hi @J-Hilk, @LeLev
Code is Similar to the following :
TableView {
id:tableview
width: 500
height:200
columnWidthProvider: 50
rowHeightProvider: 20
model:TableModel
delegate:
Rectangle {
width : 50
height : 20
Text {
width: 55
height: 40
text: tabledataText
}
}
.
.
.}
ListView {
id:listview
x: 0
y:250
contentX: tableview.contentX
orientation: ListView.Horizontal
model : tableview.columns>0 ? tableview.columns:1
delegate:
Rectangle{
id: listdelegate
width :50
height: 25
Text{
anchors.fill: listdelegate
text: tableview.headerData(data,Qt.Horizontal)
}
}
} -
Hi @J-Hilk @LeLev
If I put the problem statement in other words:
I need to synch the horizontal movement of the ListView with the TableView .
The Listview is not interactable. Is there any other method other than having contentX matched.?