<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ListView of custom Component]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm trying to make a list view of a custom component.<br />
This component is called ManualFunction.qml.<br />
It is made of Rectangles, image and buttons.<br />
I would like a list of this component where I change a few properties.</p>
<p dir="auto">The properties I want to change are the text on 2 buttons, and the source of the image.<br />
The properties are define like that in the ManualFunction.qml :</p>
<pre><code>    property string textButtonR: ""
    property string textButtonL: ""
    property string imageSource: ""
</code></pre>
<p dir="auto">Here is what I tried to create the listView:</p>
<pre><code>
        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
        }
</code></pre>
<p dir="auto">But I only get one ManualFunction without sources and Text in button. I may have misunderstood the way ListView works.<br />
Can you please help me make this works ?</p>
]]></description><link>https://forum.qt.io/topic/94712/listview-of-custom-component</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 23:03:01 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/94712.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Sep 2018 10:21:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ListView of custom Component on Tue, 18 Sep 2018 11:44:43 GMT]]></title><description><![CDATA[<p dir="auto">Thank you ! The list element where on top of eachother. I just modified the ManualFunction.qml to correct this by setting a height.</p>
]]></description><link>https://forum.qt.io/post/482076</link><guid isPermaLink="true">https://forum.qt.io/post/482076</guid><dc:creator><![CDATA[DavidM29]]></dc:creator><pubDate>Tue, 18 Sep 2018 11:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to ListView of custom Component on Tue, 18 Sep 2018 10:53:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davidm29">@<bdi>DavidM29</bdi></a> hi,</p>
<p dir="auto">for a <strong>ManualFunction.qml</strong> defined like this;<br />
<a href="//ManualFunction.qml" target="_blank" rel="noopener noreferrer nofollow ugc">//ManualFunction.qml</a></p>
<pre><code>import 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
        }
    }
}

</code></pre>
<p dir="auto"><a href="//main.qml" target="_blank" rel="noopener noreferrer nofollow ugc">//main.qml</a></p>
<pre><code>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
   }
 }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/482065</link><guid isPermaLink="true">https://forum.qt.io/post/482065</guid><dc:creator><![CDATA[ODБOï]]></dc:creator><pubDate>Tue, 18 Sep 2018 10:53:38 GMT</pubDate></item><item><title><![CDATA[Reply to ListView of custom Component on Tue, 18 Sep 2018 10:44:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gojir4">@<bdi>Gojir4</bdi></a> Thank you,<br />
It kind of works. I have now one element with the data I want in the button and image. But why do I have only one element ? I put three list element in my ListModel.<br />
Could they possibly be on top of the other ?</p>
]]></description><link>https://forum.qt.io/post/482064</link><guid isPermaLink="true">https://forum.qt.io/post/482064</guid><dc:creator><![CDATA[DavidM29]]></dc:creator><pubDate>Tue, 18 Sep 2018 10:44:24 GMT</pubDate></item><item><title><![CDATA[Reply to ListView of custom Component on Tue, 18 Sep 2018 10:37:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davidm29">@<bdi>DavidM29</bdi></a>  Hi,</p>
<p dir="auto">You need to bind value from model to your delegate.</p>
<pre><code> Component{
            id: del
            ManualFunction{
                textButtonR: model.textButtonR
                textButtonL: model.textButtonL
                imageSource: model.imageSource
            }
        }
</code></pre>
]]></description><link>https://forum.qt.io/post/482063</link><guid isPermaLink="true">https://forum.qt.io/post/482063</guid><dc:creator><![CDATA[Gojir4]]></dc:creator><pubDate>Tue, 18 Sep 2018 10:37:07 GMT</pubDate></item></channel></rss>