i need to change the order of row elements in gridview
-
Hi All,
I'm using a gridview in QML which is being populated by a QList.Currently I have it displayed 4 items per row in QML in following order.
[ITEM1] [ITEM2] [Item3] [item4]
[ITEM5] [ITEM6] [Item7] [item8]
[ITEM9] [ITEM10] [Item11] [item12]Now I wanted to populate the Items order in following way.
[ITEM1] [ITEM2] [Item3] [item4]
[ITEM8] [ITEM7] [Item6] [item5]
[ITEM9] [ITEM10] [Item11] [item12]any ways complete my requirement by using Grid View or
please suggest any other methods to fulfill my requirement.Thanks.
-
@sainaresh
TheGridView
fills the elements in row-major fashion, i.e. by row, so make sure yourQList
fills the data in the order expected by the view.
If you can't change the element order of theQList
then you need to use an index lookup array to map QList indices to GridView indices.GridView { property var gridIdx = [0,1,2,3,7,6,5,4,8,9,10,11] model: Array.from(mylist) delegate: Text { text: mylist[gridIdx[index]] } }
Or something like that. I remember reading somewhere that it is discouraged to use the
index
property within a delegate, and so normally you would usemodelData
here instead ofmylist[index]
... -
@Diracsbracket said in i need to change the order of row elements in gridview:
I remember reading somewhere that it is discouraged to use the index property within a delegate
This makes no sense to me. modelData is not available in every delegate. It depends upon the model data sources. But index is always available.
-
@fcarney said in i need to change the order of row elements in gridview:
modelData is not available in every delegate
If you mean every model, then sure (or do you mean delegates with required properties that are not matched by model properties?). For models that do provide the
modelData
role though, it makes some sense.