[Development] Controlling a QtQuick ListView using its contentY shall be supported or not?

Albert Astals Cid albert.astals at canonical.com
Tue May 21 19:32:16 CEST 2013


TLDR: Controlling a ListView using its contentY doesn't work and we have a use 
case that needs it. I am volunteering to code the solution to make it work but 
the question is what solution the Qt project wants :-)


THE PROBLEM
Our design team wants a ListView with Header that behaves in a different way 
than the current Header component of ListView does. They want that if you 
scroll up when the Header is hidden the first thing that happens is that the 
header shows and then when the Header has been totally shown the list 
scrolling happens.


THE SOLUTION
A Flickable that controls the contentY of a ListView and the height of the 
Header
  flickable_control_listview_without_sections.qml
And it works :-) but...


THE PROBLEM #2
We want to have section headers in that listview and adding section headers 
makes lots of things go weird, you can see the problem in
   flickable_control_listview.qml
either by scrolling up when the list is at the top or by scrolling to the 
bottom and then pressing 1 to scroll up. The contentY of the list will not be 
at its expected location.


THE SOLUTION #2
I can workaround this by doing crazy things like on the listview 
onContentYChanged check if it is changing to the value I set it and if not 
fixing it (fixes the jittering going up from the top)
and by remembering the last "originY" when pressing the 1 to go to the top
   flickable_control_listview_workaround.qml
I consider the changes between flickable_control_listview_workaround.qml and 
flickable_control_listview.qml a huge hack and something that should not be 
needed, but we could live with that


THE PROBLEM #3
We also want to have items with different sizes in the listview
   flickable_control_listview_workaround_different_sizes.qml
If you go to the end and then press 1 to scrol to the top you'll see that my 
workaround for the baseOriginY fails


THE PROBLEM #4
We also want to have problems if the list view contains complex loaders, 
haven't had time to create a simple test case for it


THE REAL SOLUTION?
We would like the code from flickable_control_listview_without_sections.qml to 
work on all the cases (sections, differently sized items, loader, etc) but we 
have been told that "Using contentY to control a listview is unsupported"

We are hoping that this use case may make you change your opinion on that 
statement and accept patches that makes the code in 
flickable_control_listview_without_sections.qml (or something along the lines) 
work in all the other situations.

In case you keep the statement that noone should use contentY to control 
listviews (why not make it read-only?) we see two solutions:

1) Add to ListView a enum that switches between the current Header 
hiding/showing behaviour and the one we want. Would you guys be interested in 
that feature to be merged upstream?

2) Reimplement our own ListView based on a Flickable so that it has the 
features we need. This is the solution we prefer the least since it would 
involve a lot of code duplication

So what's your opinion, how should we implement the wanted behaviour with the 
current QtQuick items?

Thanks,
  Albert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flickable_control_listview.qml
Type: text/x-qml
Size: 5896 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130521/913dedd2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flickable_control_listview_without_sections.qml
Type: text/x-qml
Size: 5445 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130521/913dedd2/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flickable_control_listview_workaround.qml
Type: text/x-qml
Size: 6226 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130521/913dedd2/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flickable_control_listview_workaround_different_sizes.qml
Type: text/x-qml
Size: 6273 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130521/913dedd2/attachment-0003.bin>


More information about the Development mailing list