[SOLVED] ListView's flickable problems
-
wrote on 17 Sept 2011, 19:45 last edited by
Project from which you posted part of code, as i understand there are no problems with contentHeight?
Or they are just invisible? ) -
wrote on 17 Sept 2011, 19:57 last edited by
This is the solution that I have adopted to solve the problem of content height.
Two strange things in your example: ListDelegate.qml is the ListItem ? It seems you have misunderstood the role of the three elements Item, Model and Delegate.
-
wrote on 17 Sept 2011, 20:06 last edited by
It's probably when i say item i mean the item in the list, and when i say delegate, i mean the delegate. I think i do understand the role of three elements, and just build my sentences wrong.
Could you please explain what you find strange in that example?
ListDelegate.qml it is a delegate; -
wrote on 18 Sept 2011, 04:14 last edited by
I have the similar problem with ListView. The each model data provides one line of text, and the delegate shows the text with Text. And then I find two problems:
-
If I use ListView.positionViewAtIndex(index, ListView.Beginning) to position the view at certain line of text, the contentY is always incorrect.
-
If the text has large number of lines, after flicking more than 200 times, the ListView stops loading text from model. Then the listView becomes blank, no matter flick up or down...
-
-
wrote on 18 Sept 2011, 05:16 last edited by
Hi,
later today I should manage the two problems of the variable text and a text list. I apply the example I posted before in a text-only list so we can check with an example.
@alex: is possible that it is a problem of memory? The documentaion reports that the best behavior in a list is obtained when you load few elements at a time and update the list at the end of the scrolling. Thus you should manage a large number of lines loading them by blocks. As a matter of fact it is not userful to have a list longer so much than the number of elements that can be shown at a time.
A general consideration to your issue is: a correct method to show variable height elements in a list exist because most of the lists i.e. the twitter feeds programs have a final button - usually thicker than the other - showing "load more ..."
As I have a working piece of code I will post here.
-
wrote on 19 Sept 2011, 13:19 last edited by
Alicemirror: I don't think this is a memory problem, because I use QAbstractListModel to provide the data, and following is the data function that I used:
@QVariant RFileModel::data(const QModelIndex & index, int /role/) const {
int row = index.row();
return data(row);
}QVariant RFileModel::data(int row) const {
// return QVariant();
if (row < m_file_line_pos.count()) {
if (m_file->seek(m_file_line_pos[row])) {
QTextStream stream(m_file);
stream.setCodec(m_codec);
stream.setAutoDetectUnicode(true);
QString str = stream.readLine();
if (str.length() || !m_file->atEnd()) {
qDebug()<<"Read str row"<<row
<<"pos"<<m_file_line_pos[row]
<<"length"<<str.length()<<str;
return str+KNewLine;
}
else {
qDebug()<<"read file line failed, line number"<<row
<<"Position"<<m_file_line_pos[row]
<<m_file->errorString();
}
}
else {
qDebug()<<"could not seek to position/line"<<m_file_line_pos[row]<<row;
}
}
else {
qDebug()<<"row number is too large:row/max"<<row<<m_file_line_pos.count();
}
return QVariant();
}@ -
wrote on 19 Sept 2011, 13:27 last edited by
Thank yo Alex, just a ping :) I'll answer to this shortly
-
wrote on 18 Oct 2011, 15:49 last edited by
still actual
-
wrote on 18 Oct 2011, 23:49 last edited by
[quote author="Milnadar" date="1316020663"]I noticed that when (vertical) listView's items has different height, contentHeight value doesn't equal to height of all items. When changing ListView's height, contentHeight may be larger or smaller than it should be. Why is it so? How does ListView count it's contentHeight?[/quote]
When items in a vertical ListView don't have a fixed height, contentHeight is estimated. This is to avoid the cost of instantiating every item in order to query their actual height.
Regards,
Michael -
wrote on 5 Jun 2013, 09:09 last edited by
I
m sorry to bring this topic from the dead, but I still don
t see what is the solution to this problem and I need to solve this.Here is the example of the code on which I`m trying to resolve the problem with contentHeight change and also with a problem when you go to positionViewAtEnd() contentY get some strange values:
@
import QtQuick 1.1Rectangle
{
width: 360
height: 360ListView { id: lv anchors.fill: parent anchors.bottomMargin: 50 spacing: 5 model: msgmodel delegate: Rectangle { id: rect; width: lv.width; height: txt.height; Text { id: txt; width: 50; anchors.topMargin: 5; wrapMode: Text.WordWrap; text: " contentY: " + lv.contentY + "|" + lv.contentHeight + " y: " + y + " " + msgtext; } } } Text { id: btn; objectName: "btn"; signal add(); text: "Click to move at end" anchors.bottom: parent.bottom MouseArea { anchors.fill: parent onReleased: lv.positionViewAtEnd(); } }
}
@Every time I go to view end contentY at the top of the view goes more in negative value.
EDIT: I have also tried this in QtQuick 2.0 and it is working better but it still has problem when going to view end. But this time instead of going into negative value, contentY increase its value.
-
wrote on 15 Aug 2013, 09:09 last edited by
Is there any solution to this when you have ListView items with variable height?
-
wrote on 25 Jan 2014, 12:20 last edited by
Hi Mixa84.
Yes, there is a solution, but it is about to implement your own listVew .
I mark this topic as solved.
-
wrote on 9 Sept 2014, 14:15 last edited by
In my opinion ListView should be doing what it says in the docs, even if it is slow.
-
wrote on 23 Mar 2015, 12:13 last edited by
Thank you for the good discussion.
Helped me a lot to understand my problem.Even so it is kind of disappointing, that we can't even use the sizeHintRole for ListViews.
Or have an option to supply the ListView with the correct contentHeight, so it doesn't try calculate it on its own...I've the idea of wrapping the actual list view into another flick able object to kind of wrap the broken scrolling with an item i can control the scrolling better. If it works I'll paste it here.
-
Hi everyone.
I noticed that when (vertical) listView's items has different height, contentHeight value doesn't equal to height of all items. When changing ListView's height, contentHeight may be larger or smaller than it should be. Why is it so? How does ListView count it's contentHeight?
The same issue when items have different height, and i am swapping two items and trying to flick listView on item's height by changing contentY value;[edit : typo in title fixed, Eddy]
-
wrote on 27 Jul 2015, 10:02 last edited by
Well I found another solution. I post here so maybe it helps sombedody.
-
You need to declare a global property which stores the height. For example : reViewHeight
-
Put the ListView inside a transparent Rectangle: rcView, and put the rectangle inside the ScrollView
-
Add: Component.onCompleted: { reViewHeight = reViewHeight + height} in your delegate definition
-
In the ListView add: onCountChanged: { rcView.height = reViewHeight }
Done !
-
-
Well I found another solution. I post here so maybe it helps sombedody.
-
You need to declare a global property which stores the height. For example : reViewHeight
-
Put the ListView inside a transparent Rectangle: rcView, and put the rectangle inside the ScrollView
-
Add: Component.onCompleted: { reViewHeight = reViewHeight + height} in your delegate definition
-
In the ListView add: onCountChanged: { rcView.height = reViewHeight }
Done !
-