Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. i need to change the order of row elements in gridview
Forum Updated to NodeBB v4.3 + New Features

i need to change the order of row elements in gridview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 523 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sainaresh
    wrote on last edited by
    #1

    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.

    DiracsbracketD 1 Reply Last reply
    0
    • S sainaresh

      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.

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @sainaresh
      The GridView fills the elements in row-major fashion, i.e. by row, so make sure your QList fills the data in the order expected by the view.
      If you can't change the element order of the QList 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 use modelData here instead of mylist[index]...

      1 Reply Last reply
      1
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        @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.

        C++ is a perfectly valid school of magic.

        DiracsbracketD 1 Reply Last reply
        0
        • fcarneyF fcarney

          @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.

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @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.

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            I would say don't do this with index:

            property var list: [...]
            
            ListView {
              model: list
              delegate: Item {
                list[index]
              }
            }
            

            So now I get what you mean. Yes, in that case modelData makes sense.

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved