Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 0.93 KB | None | 0 0
  1. // A simple model and view example in QML
  2.  
  3.  
  4. import QtQuick 2.12
  5. import QtQuick.Window 2.12
  6. import QtQuick.Controls 2.12
  7.  
  8.  
  9. Window {
  10.     visible: true
  11.     width: 640
  12.     height: 480
  13.     title: qsTr("Hello World")
  14.  
  15.     // the model
  16.     ListModel{
  17.         id: listModel
  18.         ListElement{
  19.             name: "John Smith"
  20.             age: 19
  21.         }
  22.         ListElement{
  23.             name: "Peter Parker"
  24.             age: 22
  25.         }
  26.         ListElement{
  27.             name: "Elton John"
  28.             age: 35
  29.         }
  30.     }
  31.  
  32.     // the view
  33.     ListView{
  34.         id: listView
  35.         anchors.fill: parent
  36.         model: listModel
  37.         // the delegate
  38.         delegate: Column{
  39.             Text {text: name}
  40.             Text {text: age}
  41.         }
  42.     }
  43.     Button{
  44.         x: 270
  45.         y: 220
  46.         // easily change the last element's name
  47.         onClicked: listModel.get(2).name = "James Bond"
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement