How to display a grid of non-uniform cells ?
-
wrote on 12 Jul 2017, 12:28 last edited by
Hello,
My app has a picture viewing element to it, right now I'm usingGridview
to display image thumbnails to the user. I want the thumbnail to include the whole image so I use thefillMode: Image.PreserveAspectFit
. However different images have different aspect ratios, and as a result of that I have a lot of unused space.I wonder if it's possible to use something like
Gridview
that doesn't force all the cells to be of the same size ...
For example like it's done in Google Photos:
As you can see the thumbnails are in the same height, but of different width. I want to know how to achieve the same thing with QML ?
-
Hello,
My app has a picture viewing element to it, right now I'm usingGridview
to display image thumbnails to the user. I want the thumbnail to include the whole image so I use thefillMode: Image.PreserveAspectFit
. However different images have different aspect ratios, and as a result of that I have a lot of unused space.I wonder if it's possible to use something like
Gridview
that doesn't force all the cells to be of the same size ...
For example like it's done in Google Photos:
As you can see the thumbnails are in the same height, but of different width. I want to know how to achieve the same thing with QML ?
@Curtwagner1984
see QTBUG-57549
Unfortunately i do not find much time to finish my QML extension plugin, which contains such layout element. -
wrote on 12 Jul 2017, 18:21 last edited by
Maybe
Flow
can suit You? -
@Curtwagner1984
see QTBUG-57549
Unfortunately i do not find much time to finish my QML extension plugin, which contains such layout element.@raven-worx
Where did you find a good ref for the Masonry algorithm ? -
@raven-worx
Where did you find a good ref for the Masonry algorithm ?@mrjj said in How to display a grid of non-uniform cells ?:
Where did you find a good ref for the Masonry algorithm ?
There are some algorithmns on the web. Basically i looked at various JavaScript implementations and based on them i implemented it in QML/C++.
There are more simple ones and more sophisticated ones available.@SeeLook
The problem with theFlow
element is that it doesn't takes care of the uniform row height. But which could be easily achieved though i guess by setting a fixed height to the items.
But achieving a "filled width" isn't that easy. -
@mrjj said in How to display a grid of non-uniform cells ?:
Where did you find a good ref for the Masonry algorithm ?
There are some algorithmns on the web. Basically i looked at various JavaScript implementations and based on them i implemented it in QML/C++.
There are more simple ones and more sophisticated ones available.@SeeLook
The problem with theFlow
element is that it doesn't takes care of the uniform row height. But which could be easily achieved though i guess by setting a fixed height to the items.
But achieving a "filled width" isn't that easy.@raven-worx
Ok, i did see the java script ones but wanted language neutral explanation but
i guess it a variant of bin packing that is used. -
@raven-worx
Ok, i did see the java script ones but wanted language neutral explanation but
i guess it a variant of bin packing that is used.@mrjj said in How to display a grid of non-uniform cells ?:
i guess it a variant of bin packing that is used.
yes exactly, basically it's bin packing. You can design it really simple or pretty smart. There are numerous ways to implement such layout. Depending on the features desired.
My implementation for example has the ability to stretch a certain item over 2 columns/rows. Making an item more present in the layout.
I hope i can provide the plugin sometime this year. Will make an anouncement in the showcase sub-forum ;)
-
@mrjj said in How to display a grid of non-uniform cells ?:
i guess it a variant of bin packing that is used.
yes exactly, basically it's bin packing. You can design it really simple or pretty smart. There are numerous ways to implement such layout. Depending on the features desired.
My implementation for example has the ability to stretch a certain item over 2 columns/rows. Making an item more present in the layout.
I hope i can provide the plugin sometime this year. Will make an anouncement in the showcase sub-forum ;)
@raven-worx
Oh that sounds helpful.
Is the project on git or still private ?Ok, i hope u get some time.
Thx
-
@raven-worx
Oh that sounds helpful.
Is the project on git or still private ?Ok, i hope u get some time.
Thx
-
@raven-worx
Super
QrwAndroid sounds awesome :) -
wrote on 13 Jul 2017, 12:23 last edited by
@SeeLook said in How to display a grid of non-uniform cells ?:
Maybe
Flow
can suit You?As far as I can see
Flow
doesn't work with a model likeGridview
does. -
wrote on 13 Jul 2017, 12:27 last edited by
@Curtwagner1984
And what if to squeezeRepeater
inside theFlow
? -
@Curtwagner1984
And what if to squeezeRepeater
inside theFlow
?wrote on 13 Jul 2017, 12:32 last edited by@SeeLook said in How to display a grid of non-uniform cells ?:
@Curtwagner1984
And what if to squeezeRepeater
inside theFlow
?I don't know.
Gridview
creates and destroys delegates as needed. If I'll put a repeater inFlow
and I have let's say 500 images, they would all have to be loaded to memory. -
wrote on 13 Jul 2017, 12:42 last edited by
I've already tried a
Repeater
with dynamically changed model size. Seemed to work and when size was decreased items were deleted (I believe...)
But better I will not mess You up. This is already out of my experience. -
wrote on 13 Jul 2017, 12:54 last edited by
Can you elaborate a bit more about how and what you did, so that I may try it too ?
-
wrote on 13 Jul 2017, 13:10 last edited by
If I were You, I might try something like this:
Flow { Repeater { model: yourData.length Image { source: yourData[index] sourceSize.height: 200 // or other fixed value } } }
If
yourData
isQStringList
or just QML array of strings, it can be directly set as a model of theRepeater
:model: yourData
and accessible inside
Image
this way:source: modelData
I hope this is some clue for You
-
If I were You, I might try something like this:
Flow { Repeater { model: yourData.length Image { source: yourData[index] sourceSize.height: 200 // or other fixed value } } }
If
yourData
isQStringList
or just QML array of strings, it can be directly set as a model of theRepeater
:model: yourData
and accessible inside
Image
this way:source: modelData
I hope this is some clue for You
wrote on 13 Jul 2017, 13:15 last edited byThis could work... I'll have to check if it disposes of elements that aren't visible.
-
wrote on 13 Jul 2017, 13:25 last edited by
There has to be
Flickable
that wraps all... -
wrote on 13 Jul 2017, 13:49 last edited by
@SeeLook Looks like the
model
can be aQAbstructListModel
which is exactly what I use...
It's interesting, I'll try this out.Other problems are the insert and remove function that
GridView
supports, as well as theshouldfechmore
andfetchmore
functions. (implemented inQAbstructListModel
)
1/19