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. How to iterate for each element of collection
Forum Updated to NodeBB v4.3 + New Features

How to iterate for each element of collection

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 777 Views 1 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.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #1

    Hello,
    I got some trouble with my collection of displayed elements.

    The code is look like:

    @ ListModel {
    id: boardModel
    }

      GridView{
         id: myGridView
         anchors.fill: myBoard
         model: boardModel
         cellHeight: myBoard.frameSize
         cellWidth: myBoard.frameSize
         delegate: SingleTile{}
        }
      function flipFrames(which){
    
          for(var index=0;index<myGridView.count;++index){
              myGridView.currentIndex = index
              myGridView.currentItem.setFlipped(which)
          }
          myGridView.currentIndex = which
      } @
    

    In function flipFrames after clicking on one element form the listModel I execute function from SingleTile object for each element. This solution has some issue because when Im changing currentIndex the window sometims start to move.

    Does anybody knows how to do something like that without changing currentIndex value ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      David Stiel
      wrote on last edited by
      #2

      Hi

      I would probably do something like
      @
      GridView{
      id: myGridView
      anchors.fill: myBoard
      model: boardModel
      cellHeight: myBoard.frameSize
      cellWidth: myBoard.frameSize
      property int which : -1 //new
      delegate: SingleTile{
      id : theDelegate
      Connections{ //new
      target : myGridView
      onWhichChanged :{
      theDelegate.setFlipped(myGridView.which);
      }
      }
      }
      }

      function flipFrames(which){
      myGridView.which = which;
      }
      @

      The idea (which I find useful with QML) is to use property bindings and let each element act individually. This is a bit different from c++ where we are used to looping over a collection and tell each element what to do.

      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