Qml - ListView
-
@Ibrahim QQC2 doesnot have a
ListViewcomponent. You will have to use the one provided in QtQuick module.
Have a look at this example:
http://doc.qt.io/qt-5/qtquickcontrols2-chattutorial-example.html#chapter-2-listsIn the same way you can create a delegate which will contain 2 Rectangle for the random number and the text.
I think TableView is more appropriate component here.
-
@Ibrahim QQC2 doesnot have a
ListViewcomponent. You will have to use the one provided in QtQuick module.
Have a look at this example:
http://doc.qt.io/qt-5/qtquickcontrols2-chattutorial-example.html#chapter-2-listsIn the same way you can create a delegate which will contain 2 Rectangle for the random number and the text.
I think TableView is more appropriate component here.
-
@Ibrahim
ListModelis only meant to hold the data. If your aim is to fill this model with your data you can use append to add the data dynamically:ListModel { Component.onCompleted: { append({no: index; name: "Noah"}) } }Use for loop instead of
Repeaterto do this multiple times.Repeaterhas a different purpose. -
@Ibrahim
ListModelis only meant to hold the data. If your aim is to fill this model with your data you can use append to add the data dynamically:ListModel { Component.onCompleted: { append({no: index; name: "Noah"}) } }Use for loop instead of
Repeaterto do this multiple times.Repeaterhas a different purpose. -
@Ibrahim Here's a simple implementation of the above with
ListViewand custom delegate:import QtQuick 2.5 Rectangle { width: 200; height: 200 property Component _button: Button {} property Component _textfield: TextField {} property Component _switch: Switch {} ListModel { id: model Component.onCompleted: { append({ name: "button" }) append({ name: "textfield" }) append({ name: "switch" }) } } Component { id: delegate Row { Rectangle { width: 100; height: 50 border.color: "black" border.width: 1 Text { anchors.centerIn: parent text: name } } Rectangle { id: rect width: 100; height: 50 border.color: "black" border.width: 1 Component.onCompleted: { var obj if(name=="button") { obj = _button.createObject(rect) obj.text = "Click Me!" } else if(name=="textfield") { obj = _textfield.createObject(rect) } else if(name=="switch") { obj = _switch.createObject(rect) } obj.anchors.fill = rect } } } } ListView { anchors.fill: parent model: model delegate: delegate } }You can study it and try to improve it :)

