Advertisement
Guest User

Untitled

a guest
Jul 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.23 KB | None | 0 0
  1. Item {
  2.     anchors.fill: parent
  3.     Component {
  4.         id: quadrado1
  5.         Rectangle {
  6.             width: 100
  7.             height: 100
  8.             color: "red"
  9.         }
  10.     }
  11.  
  12.     Component {
  13.         id: quadrado2
  14.         Rectangle {
  15.             width: 100
  16.             height: 100
  17.             color: "green"
  18.         }
  19.     }
  20.  
  21.     Component {
  22.         id: quadrado3
  23.         Rectangle {
  24.             width: 100
  25.             height: 100
  26.             color: "blue"
  27.         }
  28.     }
  29.  
  30.     ListModel {
  31.         id: modelo
  32.         Component.onCompleted: {
  33.             /// ListModel não suporta apontar para variáveis ou componentes,
  34.             /// entao alimentamos ele posteriormente:
  35.             modelo.append({nome: "q1", componente: quadrado1})
  36.             modelo.append({nome: "q2", componente: quadrado2})
  37.             modelo.append({nome: "q2", componente: quadrado3})
  38.         }
  39.     }
  40.  
  41.     ListView {
  42.         clip: true
  43.         anchors.fill: parent
  44.         model: modelo
  45.  
  46.         delegate: ColumnLayout {
  47.             Text {
  48.                 id: identificador
  49.                 text: model.nome
  50.             }
  51.             Loader {
  52.                 sourceComponent: model.componente
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement