<?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[Centralize multiple delegate for different graphical objects in MapItemView]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/75141/delegate-for-different-graphical-objects-in-mapitemview">Delegate for different graphical objects in MapItemView</a></p>
<p dir="auto">Hi<br />
i'm reopening this old subject as i struggling with the exact same issue.</p>
<p dir="auto">To sum it up i'd like to have a qml file to centralise the delegates that will be used to print  items in my MapItemView.</p>
<p dir="auto">Here's where i'm at :</p>
<p dir="auto">In my main map view :</p>
<pre><code>MapItemView
{
    id: mapMarkers
    model: MapMarkerModels{}
    delegate: MapMarkerMultiDelegate{}
}
</code></pre>
<p dir="auto">MapMarkerModels.qml</p>
<pre><code>ListModel
{
    id: someModels
    ListElement {type: "cursor"; lat: 43.778958; lon:3.812109}
    ListElement {type: "circle"; lat: 43.788958; lon:3.812109}
    ListElement {type: "circle"; lat: 43.798958; lon:3.812109}
}
</code></pre>
<p dir="auto">and MapMarkerMultiDelegate.qml</p>
<pre><code>Loader
{
    id: mapMarkerMultiDelegate
    sourceComponent: getDelegate(type)

    function getDelegate(t) {
        switch(t)
        {
            case "cursor": return cursorDelegate;
            case "circle": return circleDelegate;
            default: return circleDelegate;
        }
    }

    Component
    {
        id: cursorDelegate
        MapQuickItem
        {
            id: cursor
            anchorPoint.x: rect.width / 2
            anchorPoint.y:  rect.height / 2
            coordinate
            {
                latitude: lat
                longitude: lon
            }

            sourceItem:
                Rectangle
                {
                    id: rect
                    width: 25
                    height: 25
                    color: "blue"
                }
        }
    }

    Component
    {
        id: circleDelegate
        MapCircle
        {
            center
            {
                latitude: lat
                longitude: lon
            }
            radius: 500.0
            color: 'green'
            border.width: 3
        }
    }
}
</code></pre>
<p dir="auto">It doesn't show anything on the map.<br />
If y break in "getDelegate(type)" it seems to be returning the good component.<br />
But I get a message in the output :<br />
"addDelegateToMap called with a  MapMarkerMultiDelegate_QMLTYPE_1"</p>
<p dir="auto">If i remove the Loader and simply put one of the Component in the MapMarkerMultiDelegate.qml file it works fine and print what i want.</p>
<p dir="auto">I've only be playing with Qt for a few days so i might be doing everything wrong. Still this is tickeling me so if any of you have an idea =)</p>
]]></description><link>https://forum.qt.io/topic/147875/centralize-multiple-delegate-for-different-graphical-objects-in-mapitemview</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 08:59:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/147875.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Aug 2023 22:01:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Centralize multiple delegate for different graphical objects in MapItemView on Mon, 14 Aug 2023 08:45:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> said in <a href="/post/768599">Centralize multiple delegate for different graphical objects in MapItemView</a>:</p>
<blockquote>
<p dir="auto">DelegateChooser</p>
</blockquote>
<p dir="auto">Well it works like a charm, thank you =)</p>
<p dir="auto">Here the updated QML just for the next one that will have the same problem.</p>
<p dir="auto">MapMarkerMultiDelegate.qml</p>
<pre><code>DelegateChooser
{
    id: mapMarkerDelegateChooser
    role: "type"

    DelegateChoice
    {
        id: cursorDelegate
        roleValue: "cursor"
        MapQuickItem
        {
            id: cursor
            anchorPoint.x: rect.width / 2
            anchorPoint.y:  rect.height / 2
            coordinate
            {
                   latitude: lat
                   longitude: lon
            }
             sourceItem:
                Rectangle
                {
                    id: rect
                    width: 25
                    height: 25
                    color: "blue"
                }
        }
    }

    DelegateChoice
    {
        id: circleDelegate
        roleValue: "circle"
        MapCircle
        {
            center: markerCoordinate
            radius: 500.0
            color: 'green'
            border.width: 3
        }
    }
}
</code></pre>
<p dir="auto">And thx again !</p>
]]></description><link>https://forum.qt.io/post/768673</link><guid isPermaLink="true">https://forum.qt.io/post/768673</guid><dc:creator><![CDATA[Coubz]]></dc:creator><pubDate>Mon, 14 Aug 2023 08:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to Centralize multiple delegate for different graphical objects in MapItemView on Sun, 13 Aug 2023 14:05:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/coubz">@<bdi>Coubz</bdi></a> Use DelegateChooser instead of Loader.<br />
A Loader is an Item but MapItemView needs a MapItem.</p>
]]></description><link>https://forum.qt.io/post/768599</link><guid isPermaLink="true">https://forum.qt.io/post/768599</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Sun, 13 Aug 2023 14:05:33 GMT</pubDate></item></channel></rss>