ListView of custom Component
Solved
QML and Qt Quick
-
Hello,
I'm trying to make a list view of a custom component.
This component is called ManualFunction.qml.
It is made of Rectangles, image and buttons.
I would like a list of this component where I change a few properties.The properties I want to change are the text on 2 buttons, and the source of the image.
The properties are define like that in the ManualFunction.qml :property string textButtonR: "" property string textButtonL: "" property string imageSource: ""
Here is what I tried to create the listView:
ListModel { id: myModel ListElement { textButtonR: "Open" textButtonL: "Close" imageSource: "../img/sun.svg" } ListElement { textButtonR: "Open" textButtonL: "Close" imageSource: "../img/sun.svg" } ListElement { textButtonR: "Open" textButtonL: "Close" imageSource: "../img/sun.svg" } } Component{ id: del ManualFunction{ } } ListView{ anchors.fill: parent anchors.horizontalCenter: parent.horizontalCenter model: myModel delegate: del }
But I only get one ManualFunction without sources and Text in button. I may have misunderstood the way ListView works.
Can you please help me make this works ? -
@DavidM29 hi,
for a ManualFunction.qml defined like this;
//ManualFunction.qmlimport QtQuick 2.0 import QtQuick.Controls 2.2 Rectangle{ id: r height: 90 width: 200 color:'indigo' property string textButtonR: "" property string imageSource: "" Column{ anchors.fill: parent Image{ source:imageSource height: 20 width: 20 } Text{ text:textButtonR } } }
Window { visible: true width: 640 height: 480 title: qsTr("Hello World") ListModel { id: myModel ListElement { btntxt: "Open" textButtonL: "Close" imgsrc: "spin.png" } ListElement { btntxt: "Open" textButtonL: "Close" imgsrc: "spin.png" } ListElement { btntxt: "Open" textButtonL: "Close" imgsrc: "spin.png" } } ListView{ anchors.fill: parent clip: true model:myModel delegate:ManualFunction{ imageSource: imgsrc textButtonR: btntxt + " " + index } } }