[Qt-qml] How to update item within a Row

Mark Constable markc at renta.net
Tue Jan 4 06:08:57 CET 2011


On 2011-01-03, Abhishek wrote:
> As i understand(check qt/src/graphicsitems/qdeclarativerepeater.cpp)
> *Repeater* will create all element dynamically so no Id for each
> item and also there is no method or property which returns the list
> of item created by Repeater and same goes to Row, it also doesn't
> have any method or property to give the list of Item in Row so one
> cant Iterate over and find the Item at given Index.

Newb attempt #2. So if I at least avoid using Repeater and hard
wire some Components then how do I reference any one of them
from the outside? I want to dynamically load up these "desktop"
containers with "applications" ie; the demos/declarative/rssnews
example into, say, "Desktop 2".

  Row {
    id: desk
    width: rootWidth
    height: rootHeight
    Desk { x: rootWidth * 0; deskTitle: "<h1>Desktop 1</h1>" }
    Desk { x: rootWidth * 1; deskTitle: "<h1>Desktop 2</h1>" }
    Desk { x: rootWidth * 2; deskTitle: "<h1>Desktop 3</h1>" }
    // [... * 10]
  }

// Desk.qml
import QtQuick 1.0
Rectangle {
  property alias deskTitle: title.text
  width: rootWidth
  height: rootHeight
  color: "#3f3f3f"
  Text {
    id: title
    anchors.centerIn: parent
  }
}

FWIW I switch between them like this below. I don't want to use
ListElements which are destroyed when they are out of view because
the "applications" could still be active and pulling in feeds in
the case of rssnews.

  property int current: 0

  Keys.onPressed: {
    switch(event.key) {
    case Qt.Key_Right: {
      current = (current == 9) ? 0 : current+1
      desk.x = -(rootWidth * current) } break;
    case Qt.Key_Left: {
      current = (current == 0) ? 9 : current-1
      desk.x = -(rootWidth * current) } break;
    }
  }

--markc


More information about the Qt-qml mailing list